LibPkg
unpack.h
Go to the documentation of this file.
1 // This file is part of LibPkg.
2 // Copyright � 2003-2005 Graham Shaw.
3 // Copyright � 2013-2014 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_UNPACK
8 #define LIBPKG_UNPACK
9 
10 #include <string>
11 #include <set>
12 #include <tr1/functional>
13 #include "string.h"
14 
15 #include "libpkg/auto_dir.h"
16 #include "libpkg/thread.h"
17 #include "libpkg/log.h"
18 
19 namespace pkg {
20 
21 using std::string;
22 
23 class pkgbase;
24 class zipfile;
25 class log;
26 class triggers;
27 class trigger_run;
28 class trigger;
29 
32  bool operator() (const std::string& a, const std::string& b) const {
33  return stricmp(a.c_str(), b.c_str()) < 0;
34  }
35 };
36 
38 class unpack:
39  public thread
40 {
41 public:
43  typedef unsigned long long size_type;
44 
46  static const size_type npos=static_cast<size_type>(-1);
47 
50  {
106  };
107 private:
109  pkgbase& _pb;
110 
112  state_type _state;
113 
116  auto_dir _ad;
117 
119  zipfile* _zf;
120 
122  string _pkgname;
123 
125  size_type _files_done;
126 
128  size_type _files_total;
129 
131  size_type _bytes_done;
132 
134  size_type _bytes_total;
135 
137  size_type _files_total_unpack;
138 
140  size_type _files_total_remove;
141 
143  size_type _bytes_total_unpack;
144 
147  string _message;
148 
151  std::set<string> _packages_to_unpack;
152 
155  std::set<string> _packages_pre_unpacked;
156 
159  std::set<string> _packages_being_unpacked;
160 
163  std::set<string> _packages_unpacked;
164 
167  std::set<string> _packages_to_remove;
168 
171  std::set<string> _packages_being_removed;
172 
175  std::set<string> _packages_removed;
176 
179  std::set<string> _files_to_unpack;
180 
183  std::set<string> _files_being_unpacked;
184 
187  std::set<string> _files_unpacked;
188 
191  std::set<string, case_insensitive_cmp> _files_to_remove;
192 
195  std::set<string> _files_being_removed;
196 
199  std::set<string> _files_removed;
200 
202  std::set<string> _packages_cannot_process;
203 
206  std::set<string, case_insensitive_cmp> _files_that_conflict;
207 
210  std::set<string> _existing_module_packages;
211 
213  triggers *_triggers;
214 
216  trigger_run *_trigger_run;
217 
219  trigger *_trigger;
220 
222  pkg::log *_log;
223 
225  std::tr1::function<void(LogCode code, const std::string &item, const std::string &what)> _warning;
226 
228  bool _state_text_changed;
230  std::string _state_text;
231 
232 public:
237  unpack(pkgbase& pb,const std::set<string>& packages);
238 
240  virtual ~unpack();
241 
246  { return _state; }
247 
252  { return _files_done; }
253 
258  { return _files_total; }
259 
264  { return _bytes_done; }
265 
270  { return _bytes_total; }
271 
277  string message() const
278  { return _message; }
279 
284  {
285  if (_state_text_changed) {_state_text_changed=false; return true;}
286  else return false;
287  }
288 
290  const std::string &state_text() const
291  { return _state_text; }
292 
299  const std::set<string>& packages_cannot_process() const
300  { return _packages_cannot_process; }
301 
308  const std::set<string, case_insensitive_cmp>& files_that_conflict() const
309  { return _files_that_conflict; }
310 
312  void use_trigger_run(trigger_run *tr);
313 
315  void log_to(pkg::log *use_log);
316 
318  void warning_func(std::tr1::function<void(LogCode code, const std::string &item, const std::string &what)> &f) {_warning = f;}
319 
327 
328 protected:
329  void poll();
330 private:
336  void _poll();
337 
339  void state(state_type new_state);
340 
342  void state_text(const std::string &text);
343 
350  void read_manifest(std::set<string>& mf,const string& pkgname);
351 
362  void build_manifest(std::set<string>& mf,zipfile& zf,size_type* usize=0);
363 
370  void prepare_manifest(std::set<string>& mf,const string& pkgname);
371 
377  void activate_manifest(const string& pkgname);
378 
384  void remove_manifest(const string& pkgname);
385 
389  void add_pre_install_trigger(const string &pkgname, bool has_unwind);
390 
394  void add_post_install_trigger(const string &pkgname);
395 
399  void add_pre_remove_trigger(const string &pkgname);
404  void set_post_install_unwind(const string &pkgname);
405 
411  void add_post_remove_trigger(const string &pkgname, std::set<std::string> &mf);
412 
420  void unpack_file(const string& src_pathname,const string& dst_pathname);
421 
429  void replace_file(const string& dst_pathname,bool overwrite);
430 
436  void remove_file(const string& dst_pathname);
437 
442  void remove_backup(const string& dst_pathname);
443 
448  void unwind_remove_file(const string& dst_pathname);
449 
458  void unwind_replace_file(const string& dst_pathname,bool overwrite);
459 
464  void unwind_unpack_file(const string& dst_pathname);
465 
477  bool already_installed(const control& ctrl, const std::set<string> &mf);
478 
481  void update_existing_modules();
482 
484  void unwind_existing_modules();
485 
491  void get_trigger_versions(const std::string &pkgname, std::string &old_version, std::string &new_version);
492 
493  class cannot_process;
494  class file_conflict;
495  class file_info_not_found;
496  class riscos_info_not_found;
497 };
498 
499 }; /* namespace pkg */
500 
501 #endif
const std::set< string, case_insensitive_cmp > & files_that_conflict() const
Get the set of destination pathnames that conflict with files already on the system.
Definition: unpack.h:308
The state in which old versions of files are backed up and replaced with new versions.
Definition: unpack.h:71
The state in which post remove triggers are run to unwind the actions of the pre install triggers...
Definition: unpack.h:91
A class to manage the package triggers executed during the commiting of the packages.
Definition: triggers.h:27
The state in which state_pre_remove is being backed out.
Definition: unpack.h:100
triggers * detach_triggers()
Detach triggers for use later in the commit stage.
Definition: unpack.cc:206
virtual ~unpack()
Destroy unpack object.
Definition: unpack.cc:191
The state in which state_pre_unpack is being backed out.
Definition: unpack.h:102
The state in which state_unpack is being backed out.
Definition: unpack.h:93
The state in which post install triggers are run to unwind the actions of the pre remove and/or pre i...
Definition: unpack.h:96
static const size_type npos
A null value for use in place of a byte count.
Definition: unpack.h:46
The state in which backups are deleted, and the states of packages to be removed are changed to statu...
Definition: unpack.h:78
size_type files_total() const
Get total number of files to process.
Definition: unpack.h:257
A class for unpacking and removing sets of packages.
Definition: unpack.h:38
void log_to(pkg::log *use_log)
Set the log to add the unpack messages to.
Definition: unpack.cc:201
The state in which files are unpacked from their zip archives and moved to temporary locations...
Definition: unpack.h:66
state_type
An enumeration for describing the state of the unpack operation.
Definition: unpack.h:49
A class for automatically creating and deleting directories.
Definition: auto_dir.h:20
The state in which the states of packages to be unpacked are changed to status::state_unpacked.
Definition: unpack.h:81
class to represent a trigger action from a script
Definition: trigger.h:22
bool clear_state_text_changed()
Check is state text has changed and clear the changed flag.
Definition: unpack.h:283
The state in which an error has occurred and an attempt has been made to back out changes...
Definition: unpack.h:105
The state in which pre install triggers are run.
Definition: unpack.h:68
A class to represent the content of a RiscPkg control file.
Definition: control.h:24
size_type files_done() const
Get number of files processed.
Definition: unpack.h:251
A mixin class to represent a cooperative thread.
Definition: thread.h:12
Class to log actions that occur in LibPkg.
Definition: log.h:206
size_type bytes_done() const
Get number of bytes processed.
Definition: unpack.h:263
Interface to execute a trigger.
Definition: trigger.h:66
A class for representing the collection of package database tables.
Definition: pkgbase.h:22
The state in which state_replace is being backed out.
Definition: unpack.h:88
unsigned long long size_type
A type for representing byte counts.
Definition: unpack.h:43
The state in which the pre remove triggers are run.
Definition: unpack.h:63
size_type bytes_total() const
Get total number of bytes to process.
Definition: unpack.h:269
Comparison that does not take into account the case of the string.
Definition: unpack.h:31
const char * dst_pathname
Definition: path_table.cc:21
The state in which post remove trigger copies are removed.
Definition: unpack.h:98
The state in which all operations have been successfully completed.
Definition: unpack.h:84
The state in which post remove triggers are copied so they are preserved to be run after the packages...
Definition: unpack.h:61
The state in which old versions of files that do not have replacements are backed up then removed...
Definition: unpack.h:74
unpack(pkgbase &pb, const std::set< string > &packages)
Construct unpack object.
Definition: unpack.cc:158
const std::string & state_text() const
Return the current state text.
Definition: unpack.h:290
const char * src_pathname
Definition: path_table.cc:20
The state in which the states of packages to be removed are changed to status::state_half_unpacked.
Definition: unpack.h:58
An interface class to represent a zip file.
Definition: zipfile.h:20
void poll()
Poll this thread.
Definition: unpack.cc:213
const std::set< string > & packages_cannot_process() const
Get the set of packages that cannot be processed.
Definition: unpack.h:299
The state in which state_remove is being backed out.
Definition: unpack.h:86
void use_trigger_run(trigger_run *tr)
Set the class to run triggers.
Definition: unpack.cc:196
bool operator()(const std::string &a, const std::string &b) const
Definition: unpack.h:32
LogCode
An enumeration of all the items that can be logged.
Definition: log.h:19
string message() const
Get error message.
Definition: unpack.h:277
The state in which the states of packages to be unpacked are changed to status::state_half_unpacked.
Definition: unpack.h:54
state_type state() const
Get current state of the unpack operation.
Definition: unpack.h:245
void warning_func(std::tr1::function< void(LogCode code, const std::string &item, const std::string &what)> &f)
Set the function to log and capture warnings.
Definition: unpack.h:318

Reference Manual LibPkg Version 0.6.1 (28 Jan 2015)