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  {
116  state_fail
117  };
118 private:
120  pkgbase& _pb;
121 
123  state_type _state;
124 
127  auto_dir _ad;
128 
130  zipfile* _zf;
131 
133  string _pkgname;
134 
136  size_type _files_done;
137 
139  size_type _files_total;
140 
142  size_type _bytes_done;
143 
145  size_type _bytes_total;
146 
148  size_type _files_total_unpack;
149 
151  size_type _files_total_remove;
152 
154  size_type _bytes_total_unpack;
155 
158  string _message;
159 
162  std::set<string> _packages_to_unpack;
163 
166  std::set<string> _packages_pre_unpacked;
167 
170  std::set<string> _packages_being_unpacked;
171 
174  std::set<string> _packages_unpacked;
175 
178  std::set<string> _packages_to_remove;
179 
182  std::set<string> _packages_being_removed;
183 
186  std::set<string> _packages_removed;
187 
190  std::set<string> _files_to_unpack;
191 
194  std::set<string> _files_being_unpacked;
195 
198  std::set<string> _files_unpacked;
199 
202  std::set<string> _empty_dirs_to_create;
203 
206  std::set<string> _parent_dirs;
207 
210  std::set<string> _files_to_replace_by_dirs;
211 
213  std::set<string> _files_replaced_by_dirs;
214 
217  std::set<string, case_insensitive_cmp> _files_to_remove;
218 
221  std::set<string, case_insensitive_cmp> _dirs_to_remove;
222 
225  std::set<string> _files_being_removed;
226 
229  std::set<string> _files_removed;
230 
233  std::set<string> _empty_dirs_to_check;
235  std::set<string> _dirs_removed;
237  std::set<string> _dirs_created;
238 
240  std::set<string> _packages_cannot_process;
241 
244  std::set<string, case_insensitive_cmp> _files_that_conflict;
245 
248  std::set<string> _existing_module_packages;
249 
251  triggers *_triggers;
252 
254  trigger_run *_trigger_run;
255 
257  trigger *_trigger;
258 
260  pkg::log *_log;
261 
263  std::tr1::function<void(LogCode code, const std::string &item, const std::string &what)> _warning;
264 
266  bool _state_text_changed;
268  std::string _state_text;
269 
271  std::string _exception_item;
272 
273 public:
278  unpack(pkgbase& pb,const std::set<string>& packages);
279 
281  virtual ~unpack();
282 
287  { return _state; }
288 
292  size_type files_done() const
293  { return _files_done; }
294 
298  size_type files_total() const
299  { return _files_total; }
300 
304  size_type bytes_done() const
305  { return _bytes_done; }
306 
310  size_type bytes_total() const
311  { return _bytes_total; }
312 
318  string message() const
319  { return _message; }
320 
325  {
326  if (_state_text_changed) {_state_text_changed=false; return true;}
327  else return false;
328  }
329 
331  const std::string &state_text() const
332  { return _state_text; }
333 
340  const std::set<string>& packages_cannot_process() const
341  { return _packages_cannot_process; }
342 
349  const std::set<string, case_insensitive_cmp>& files_that_conflict() const
350  { return _files_that_conflict; }
351 
353  void use_trigger_run(trigger_run *tr);
354 
356  void log_to(pkg::log *use_log);
357 
359  void warning_func(std::tr1::function<void(LogCode code, const std::string &item, const std::string &what)> &f) {_warning = f;}
360 
367  triggers *detach_triggers();
368 
369 protected:
370  void poll();
371 private:
377  void _poll();
378 
380  void pre_unpack_check_files();
382  void pre_unpack_check_empty_dirs();
384  void pre_unpack_check_parent_dirs();
386  void pre_unpack_select_package();
388  void pre_remove_select_package();
390  void unpack_select_package();
391 
393  void state(state_type new_state);
394 
396  void state_text(const std::string &text);
397 
404  void read_manifest(std::set<string>& mf,const string& pkgname);
405 
416  void build_manifest(std::set<string>& mf,zipfile& zf,size_type* usize=0);
417 
424  void prepare_manifest(std::set<string>& mf,const string& pkgname);
425 
431  void activate_manifest(const string& pkgname);
432 
438  void remove_manifest(const string& pkgname);
439 
443  void add_pre_install_trigger(const string &pkgname, bool has_unwind);
444 
448  void add_post_install_trigger(const string &pkgname);
449 
453  void add_pre_remove_trigger(const string &pkgname);
458  void set_post_install_unwind(const string &pkgname);
459 
465  void add_post_remove_trigger(const string &pkgname, std::set<std::string> &mf);
466 
474  void unpack_file(const string& src_pathname,const string& dst_pathname);
475 
483  void replace_file(const string& dst_pathname,bool overwrite);
484 
490  void remove_file(const string& dst_pathname);
491 
496  void remove_backup(const string& dst_pathname);
501  void unwind_remove_file(const string& dst_pathname);
502 
511  void unwind_replace_file(const string& dst_pathname,bool overwrite);
512 
517  void unwind_unpack_file(const string& dst_pathname);
518 
530  bool already_installed(const control& ctrl, const std::set<string> &mf);
531 
534  void update_existing_modules();
535 
537  void unwind_existing_modules();
538 
544  void get_trigger_versions(const std::string &pkgname, std::string &old_version, std::string &new_version);
545 
546  class cannot_process;
547  class file_conflict;
548  class file_info_not_found;
549  class riscos_info_not_found;
550 };
551 
552 }; /* namespace pkg */
553 
554 #endif
The state in which old versions of files are backed up and replaced with new versions.
Definition: unpack.h:74
size_type files_total() const
Get total number of files to process.
Definition: unpack.h:298
The state in which post remove triggers are run to unwind the actions of the pre install triggers...
Definition: unpack.h:100
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:111
An exception class for reporting that a file information record could not be found.
Definition: unpack.cc:157
const std::set< string > & packages_cannot_process() const
Get the set of packages that cannot be processed.
Definition: unpack.h:340
The state in which state_pre_unpack is being backed out.
Definition: unpack.h:113
The state in which state_unpack is being backed out.
Definition: unpack.h:102
The state in which post install triggers are run to unwind the actions of the pre remove and/or pre i...
Definition: unpack.h:107
The namespace used to hold the package management library.
Definition: auto_dir.cc:12
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:349
bool operator()(const std::string &a, const std::string &b) const
Definition: unpack.h:32
An exception class for reporting that one or more files conflict with those already on the system...
Definition: unpack.cc:147
The state in which backups are deleted, and the states of packages to be removed are changed to statu...
Definition: unpack.h:81
size_type bytes_total() const
Get total number of bytes to process.
Definition: unpack.h:310
A class for unpacking and removing sets of packages.
Definition: unpack.h:38
size_type files_done() const
Get number of files processed.
Definition: unpack.h:292
The state in which files are unpacked from their zip archives and moved to temporary locations...
Definition: unpack.h:69
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:88
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:324
string message() const
Get error message.
Definition: unpack.h:318
The state in which empty diwas created are removed.
Definition: unpack.h:93
The state in which pre install triggers are run.
Definition: unpack.h:71
A class to represent the content of a RiscPkg control file.
Definition: control.h:24
The state in which files are moved that will overwritten by auto create directories.
Definition: unpack.h:66
A mixin class to represent a cooperative thread.
Definition: thread.h:12
Class to log actions that occur in LibPkg.
Definition: log.h:215
Interface to execute a trigger.
Definition: trigger.h:66
size_type bytes_done() const
Get number of bytes processed.
Definition: unpack.h:304
A class for representing the collection of package database tables.
Definition: pkgbase.h:24
An exception class for reporting that one or more packages cannot be processed.
Definition: unpack.cc:137
The state in which state_replace is being backed out.
Definition: unpack.h:97
The state in which any empty directories that need creating are created.
Definition: unpack.h:85
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
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
const std::string & state_text() const
Return the current state text.
Definition: unpack.h:331
The state in which post remove trigger copies are removed.
Definition: unpack.h:109
The state in which all operations have been successfully completed.
Definition: unpack.h:91
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:77
The state in which files replaced by directories are restored.
Definition: unpack.h:104
state_type state() const
Get current state of the unpack operation.
Definition: unpack.h:286
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
The state in which state_remove is being backed out.
Definition: unpack.h:95
LogCode
An enumeration of all the items that can be logged.
Definition: log.h:19
The state in which the states of packages to be unpacked are changed to status::state_half_unpacked.
Definition: unpack.h:54
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:359

Reference Manual LibPkg Version 0.6.1 (28 Jan 2015)