LibPkg
triggers.h
Go to the documentation of this file.
1 // This file is part of LibPkg.
2 //
3 // Copyright 2003-2020 Graham Shaw
4 // Copyright 2015-2020 Alan Buckley
5 //
6 // Licensed under the Apache License, Version 2.0 (the "License");
7 // you may not use this file except in compliance with the License.
8 // You may obtain a copy of the License at
9 //
10 // http://www.apache.org/licenses/LICENSE-2.0
11 //
12 // Unless required by applicable law or agreed to in writing, software
13 // distributed under the License is distributed on an "AS IS" BASIS,
14 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 // See the License for the specific language governing permissions and
16 // limitations under the License.
17 
18 #ifndef LIBPKG_TRIGGERS
19 #define LIBPKG_TRIGGERS
20 
21 #include <string>
22 #include <map>
23 #include <set>
24 
25 #include "libpkg/auto_dir.h"
26 
27 namespace pkg
28 {
29  class pkgbase;
30  class trigger;
31  class trigger_run;
32  class log;
33 
38  class triggers
39  {
40  pkgbase &_pb;
41  trigger_run *_trigger_run;
42  log *_log;
43  bool _shared_vars_deleted;
44 
47  struct trigger_info
48  {
49  trigger_info() : has_install_unwind(false), has_remove_unwind(false) {}
50  trigger_info(const std::string &oldver, const std::string &newver) :
51  old_version(oldver), new_version(newver),
52  has_install_unwind(false), has_remove_unwind(false)
53  {}
54 
56  std::string old_version;
58  std::string new_version;
60  bool has_install_unwind;
62  bool has_remove_unwind;
63  };
65  std::map<std::string, trigger_info> _packages;
67  std::set<std::string> _pre_install;
69  std::set<std::string> _post_install;
71  std::set<std::string> _pre_remove;
73  std::set<std::string> _post_remove;
75  std::set<std::string> _post_remove_files_to_copy;
77  std::set<std::string> _post_remove_files;
79  std::set<std::string> _pre_install_unwind;
81  std::set<std::string> _pre_remove_unwind;
83  auto_dir _ad;
84  public:
90  triggers(pkgbase &pb, trigger_run *tr, log *lg);
91  ~triggers();
92 
99  void add_pre_install(const std::string &pkgname, const std::string &old_version, const std::string &new_version, bool has_unwind);
100 
106  void add_post_install(const std::string &pkgname, const std::string &old_version, const std::string &new_version);
107 
113  void add_pre_remove(const std::string &pkgname, const std::string &old_version, const std::string &new_version);
114 
120  void add_post_remove(const std::string &pkgname, const std::string &old_version, const std::string &new_version);
121 
127  void add_post_install_abort(const string &pkgname, const std::string &old_version, const std::string &new_version);
128 
134  void add_post_remove_file(const std::string &filename);
135 
137  bool post_remove_files_to_copy() const;
139  bool copy_post_remove_file();
140 
142  bool pre_remove_triggers_to_run() const;
146  bool pre_install_triggers_to_run() const;
150  bool pre_install_to_unwind() const;
155  bool pre_remove_to_unwind() const;
160  bool post_remove_files_to_remove() const;
163 
165  bool post_remove_triggers_to_run() const;
169  bool post_install_triggers_to_run() const;
172 
177  void delete_shared_vars();
178  };
179 
180 }
181 
182 #endif
A class to manage the package triggers executed during the commiting of the packages.
Definition: triggers.h:38
trigger * next_pre_install_trigger()
Remove and return the next pre install trigger to run.
Definition: triggers.cc:160
bool pre_remove_triggers_to_run() const
Check if there are any pre remove triggers to run.
Definition: triggers.cc:140
bool copy_post_remove_file()
Copy one post remove trigger file for use later.
Definition: triggers.cc:119
bool post_remove_files_to_copy() const
Check if there are any post remove triggers left to copy.
Definition: triggers.cc:114
bool pre_remove_to_unwind() const
Check if there are any pre remove triggers to remove.
Definition: triggers.cc:213
void remove_post_remove_file()
Remove a post remove copied field.
Definition: triggers.cc:232
The namespace used to hold the package management library.
Definition: auto_dir.cc:23
~triggers()
Definition: triggers.cc:56
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:218
triggers(pkgbase &pb, trigger_run *tr, log *lg)
Construct the class to maintain lists and create triggers.
Definition: triggers.cc:48
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:81
A class for automatically creating and deleting directories.
Definition: auto_dir.h:31
bool post_install_triggers_to_run() const
Check if there are any post install triggers to run.
Definition: triggers.cc:185
class to represent a trigger action from a script
Definition: trigger.h:33
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:72
trigger * next_post_remove_trigger()
Remove and return the next post remove trigger to run.
Definition: triggers.cc:176
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:62
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:109
Class to log actions that occur in LibPkg.
Definition: log.h:226
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:90
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:204
Interface to execute a trigger.
Definition: trigger.h:77
bool post_remove_files_to_remove() const
Check if there are any post remove trigger copies to remove.
Definition: triggers.cc:227
A class for representing the collection of package database tables.
Definition: pkgbase.h:35
bool post_remove_triggers_to_run() const
Check if there are any post remove triggers to run.
Definition: triggers.cc:171
bool pre_install_to_unwind() const
Check if there are any pre install triggers to unwind.
Definition: triggers.cc:199
void delete_shared_vars()
Delete the shared environmental variables created by the triggers.
Definition: triggers.cc:241
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:99
bool pre_install_triggers_to_run() const
Check if there are any pre install triggers to run.
Definition: triggers.cc:155
trigger * next_post_install_trigger()
Remove and return the next postinstall trigger to run.
Definition: triggers.cc:190
trigger * next_pre_remove_trigger()
Remove and return the next pre remove trigger to run.
Definition: triggers.cc:145

Reference Manual LibPkg Version 0.9.0 (4 Sep 2020)