LibPkg
triggers.h
Go to the documentation of this file.
1 // This file is part of LibPkg.
2 // Copyright � 2003-2005 Graham Shaw.
3 // Copyright � 2015 Alan Buckley.
4 // Distribution and use are subject to the GNU Lesser General Public License,
5 // a copy of which may be found in the file !LibPkg.Copyright.
6 //
7 #ifndef LIBPKG_TRIGGERS
8 #define LIBPKG_TRIGGERS
9 
10 #include <string>
11 #include <map>
12 #include <set>
13 
14 #include "libpkg/auto_dir.h"
15 
16 namespace pkg
17 {
18  class pkgbase;
19  class trigger;
20  class trigger_run;
21  class log;
22 
27  class triggers
28  {
29  pkgbase &_pb;
30  trigger_run *_trigger_run;
31  log *_log;
32  bool _shared_vars_deleted;
33 
36  struct trigger_info
37  {
38  trigger_info() : has_install_unwind(false), has_remove_unwind(false) {}
39  trigger_info(const std::string &oldver, const std::string &newver) :
40  old_version(oldver), new_version(newver),
41  has_install_unwind(false), has_remove_unwind(false)
42  {}
43 
45  std::string old_version;
47  std::string new_version;
49  bool has_install_unwind;
51  bool has_remove_unwind;
52  };
54  std::map<std::string, trigger_info> _packages;
56  std::set<std::string> _pre_install;
58  std::set<std::string> _post_install;
60  std::set<std::string> _pre_remove;
62  std::set<std::string> _post_remove;
64  std::set<std::string> _post_remove_files_to_copy;
66  std::set<std::string> _post_remove_files;
68  std::set<std::string> _pre_install_unwind;
70  std::set<std::string> _pre_remove_unwind;
72  auto_dir _ad;
73  public:
79  triggers(pkgbase &pb, trigger_run *tr, log *lg);
80  ~triggers();
81 
88  void add_pre_install(const std::string &pkgname, const std::string &old_version, const std::string &new_version, bool has_unwind);
89 
95  void add_post_install(const std::string &pkgname, const std::string &old_version, const std::string &new_version);
96 
102  void add_pre_remove(const std::string &pkgname, const std::string &old_version, const std::string &new_version);
103 
109  void add_post_remove(const std::string &pkgname, const std::string &old_version, const std::string &new_version);
110 
116  void add_post_install_abort(const string &pkgname, const std::string &old_version, const std::string &new_version);
117 
123  void add_post_remove_file(const std::string &filename);
124 
126  bool post_remove_files_to_copy() const;
128  bool copy_post_remove_file();
129 
131  bool pre_remove_triggers_to_run() const;
135  bool pre_install_triggers_to_run() const;
139  bool pre_install_to_unwind() const;
144  bool pre_remove_to_unwind() const;
149  bool post_remove_files_to_remove() const;
152 
154  bool post_remove_triggers_to_run() const;
158  bool post_install_triggers_to_run() const;
161 
166  void delete_shared_vars();
167  };
168 
169 }
170 
171 #endif
A class to manage the package triggers executed during the commiting of the packages.
Definition: triggers.h:27
trigger * next_pre_install_trigger()
Remove and return the next pre install trigger to run.
Definition: triggers.cc:150
bool pre_remove_triggers_to_run() const
Check if there are any pre remove triggers to run.
Definition: triggers.cc:130
bool copy_post_remove_file()
Copy one post remove trigger file for use later.
Definition: triggers.cc:109
bool post_remove_files_to_copy() const
Check if there are any post remove triggers left to copy.
Definition: triggers.cc:104
bool pre_remove_to_unwind() const
Check if there are any pre remove triggers to remove.
Definition: triggers.cc:203
void remove_post_remove_file()
Remove a post remove copied field.
Definition: triggers.cc:222
The namespace used to hold the package management library.
Definition: auto_dir.cc:12
~triggers()
Definition: triggers.cc:46
trigger * next_pre_remove_unwind()
Return a post install trigger to be called to unwind the action of a pre remove trigger.
Definition: triggers.cc:208
triggers(pkgbase &pb, trigger_run *tr, log *lg)
Construct the class to maintain lists and create triggers.
Definition: triggers.cc:38
void add_pre_remove(const std::string &pkgname, const std::string &old_version, const std::string &new_version)
Add pre remove trigger to list of triggers.
Definition: triggers.cc:71
A class for automatically creating and deleting directories.
Definition: auto_dir.h:20
bool post_install_triggers_to_run() const
Check if there are any post install triggers to run.
Definition: triggers.cc:175
class to represent a trigger action from a script
Definition: trigger.h:22
void add_post_install(const std::string &pkgname, const std::string &old_version, const std::string &new_version)
Add post install trigger to list of triggers.
Definition: triggers.cc:62
trigger * next_post_remove_trigger()
Remove and return the next post remove trigger to run.
Definition: triggers.cc:166
void add_pre_install(const std::string &pkgname, const std::string &old_version, const std::string &new_version, bool has_unwind)
Add pre install trigger to list of triggers.
Definition: triggers.cc:52
void add_post_remove_file(const std::string &filename)
Add file to list of files that need to be copied so they are available to run after the package has b...
Definition: triggers.cc:99
Class to log actions that occur in LibPkg.
Definition: log.h:213
void add_post_remove(const std::string &pkgname, const std::string &old_version, const std::string &new_version)
Add post remove trigger to list of triggers.
Definition: triggers.cc:80
trigger * next_pre_install_unwind()
Return a post remove trigger to be called to unwind the action of a pre install trigger.
Definition: triggers.cc:194
Interface to execute a trigger.
Definition: trigger.h:66
bool post_remove_files_to_remove() const
Check if there are any post remove trigger copies to remove.
Definition: triggers.cc:217
A class for representing the collection of package database tables.
Definition: pkgbase.h:24
bool post_remove_triggers_to_run() const
Check if there are any post remove triggers to run.
Definition: triggers.cc:161
bool pre_install_to_unwind() const
Check if there are any pre install triggers to unwind.
Definition: triggers.cc:189
void delete_shared_vars()
Delete the shared environmental variables created by the triggers.
Definition: triggers.cc:231
void add_post_install_abort(const string &pkgname, const std::string &old_version, const std::string &new_version)
Set package being removed has a post install trigger.
Definition: triggers.cc:89
bool pre_install_triggers_to_run() const
Check if there are any pre install triggers to run.
Definition: triggers.cc:145
trigger * next_post_install_trigger()
Remove and return the next postinstall trigger to run.
Definition: triggers.cc:180
trigger * next_pre_remove_trigger()
Remove and return the next pre remove trigger to run.
Definition: triggers.cc:135

Reference Manual LibPkg Version 0.6.1 (28 Jan 2015)