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 "string.h"
13 
14 #include "libpkg/auto_dir.h"
15 #include "libpkg/thread.h"
16 
17 namespace pkg {
18 
19 using std::string;
20 
21 class pkgbase;
22 class zipfile;
23 class log;
24 
27  bool operator() (const std::string& a, const std::string& b) const {
28  return stricmp(a.c_str(), b.c_str()) < 0;
29  }
30 };
31 
33 class unpack:
34  public thread
35 {
36 public:
38  typedef unsigned long long size_type;
39 
41  static const size_type npos=static_cast<size_type>(-1);
42 
45  {
86  };
87 private:
89  pkgbase& _pb;
90 
92  state_type _state;
93 
96  auto_dir _ad;
97 
99  zipfile* _zf;
100 
102  string _pkgname;
103 
105  size_type _files_done;
106 
108  size_type _files_total;
109 
111  size_type _bytes_done;
112 
114  size_type _bytes_total;
115 
117  size_type _files_total_unpack;
118 
120  size_type _files_total_remove;
121 
123  size_type _bytes_total_unpack;
124 
127  string _message;
128 
131  std::set<string> _packages_to_unpack;
132 
135  std::set<string> _packages_pre_unpacked;
136 
139  std::set<string> _packages_being_unpacked;
140 
143  std::set<string> _packages_unpacked;
144 
147  std::set<string> _packages_to_remove;
148 
151  std::set<string> _packages_being_removed;
152 
155  std::set<string> _packages_removed;
156 
159  std::set<string> _files_to_unpack;
160 
163  std::set<string> _files_being_unpacked;
164 
167  std::set<string> _files_unpacked;
168 
171  std::set<string, case_insensitive_cmp> _files_to_remove;
172 
175  std::set<string> _files_being_removed;
176 
179  std::set<string> _files_removed;
180 
182  std::set<string> _packages_cannot_process;
183 
186  std::set<string, case_insensitive_cmp> _files_that_conflict;
187 
190  std::set<string> _existing_module_packages;
191 
193  pkg::log *_log;
194 public:
199  unpack(pkgbase& pb,const std::set<string>& packages);
200 
202  virtual ~unpack();
203 
208  { return _state; }
209 
214  { return _files_done; }
215 
220  { return _files_total; }
221 
226  { return _bytes_done; }
227 
232  { return _bytes_total; }
233 
239  string message() const
240  { return _message; }
241 
248  const std::set<string>& packages_cannot_process() const
249  { return _packages_cannot_process; }
250 
257  const std::set<string, case_insensitive_cmp>& files_that_conflict() const
258  { return _files_that_conflict; }
259 
261  void log_to(pkg::log *use_log);
262 protected:
263  void poll();
264 private:
270  void _poll();
271 
278  void read_manifest(std::set<string>& mf,const string& pkgname);
279 
290  void build_manifest(std::set<string>& mf,zipfile& zf,size_type* usize=0);
291 
298  void prepare_manifest(std::set<string>& mf,const string& pkgname);
299 
305  void activate_manifest(const string& pkgname);
306 
312  void remove_manifest(const string& pkgname);
313 
321  void unpack_file(const string& src_pathname,const string& dst_pathname);
322 
330  void replace_file(const string& dst_pathname,bool overwrite);
331 
337  void remove_file(const string& dst_pathname);
338 
343  void remove_backup(const string& dst_pathname);
344 
349  void unwind_remove_file(const string& dst_pathname);
350 
359  void unwind_replace_file(const string& dst_pathname,bool overwrite);
360 
365  void unwind_unpack_file(const string& dst_pathname);
366 
378  bool already_installed(const control& ctrl, const std::set<string> &mf);
379 
382  void update_existing_modules();
383 
385  void unwind_existing_modules();
386 
387  class cannot_process;
388  class file_conflict;
389  class file_info_not_found;
390  class riscos_info_not_found;
391 };
392 
393 }; /* namespace pkg */
394 
395 #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:257
The state in which old versions of files are backed up and replaced with new versions.
Definition: unpack.h:59
The state in which state_pre_remove is being backed out.
Definition: unpack.h:80
virtual ~unpack()
Destroy unpack object.
Definition: unpack.cc:178
The state in which state_pre_unpack is being backed out.
Definition: unpack.h:82
The state in which state_unpack is being backed out.
Definition: unpack.h:78
static const size_type npos
A null value for use in place of a byte count.
Definition: unpack.h:41
The state in which backups are deleted, and the states of packages to be removed are changed to statu...
Definition: unpack.h:66
size_type files_total() const
Get total number of files to process.
Definition: unpack.h:219
A class for unpacking and removing sets of packages.
Definition: unpack.h:33
void log_to(pkg::log *use_log)
Set the log to add the unpack messages to.
Definition: unpack.cc:181
The state in which files are unpacked from their zip archives and moved to temporary locations...
Definition: unpack.h:56
state_type
An enumeration for describing the state of the unpack operation.
Definition: unpack.h:44
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:69
The state in which an error has occurred and an attempt has been made to back out changes...
Definition: unpack.h:85
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:213
A mixin class to represent a cooperative thread.
Definition: thread.h:12
Class to log actions that occur in LibPkg.
Definition: log.h:189
size_type bytes_done() const
Get number of bytes processed.
Definition: unpack.h:225
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:76
unsigned long long size_type
A type for representing byte counts.
Definition: unpack.h:38
size_type bytes_total() const
Get total number of bytes to process.
Definition: unpack.h:231
Comparison that does not take into account the case of the string.
Definition: unpack.h:26
const char * dst_pathname
Definition: path_table.cc:20
The state in which all operations have been successfully completed.
Definition: unpack.h:72
The state in which old versions of files that do not have replacements are backed up then removed...
Definition: unpack.h:62
unpack(pkgbase &pb, const std::set< string > &packages)
Construct unpack object.
Definition: unpack.cc:150
const char * src_pathname
Definition: path_table.cc:19
The state in which the states of packages to be removed are changed to status::state_half_unpacked.
Definition: unpack.h:53
An interface class to represent a zip file.
Definition: zipfile.h:20
void poll()
Poll this thread.
Definition: unpack.cc:186
const std::set< string > & packages_cannot_process() const
Get the set of packages that cannot be processed.
Definition: unpack.h:248
The state in which state_remove is being backed out.
Definition: unpack.h:74
bool operator()(const std::string &a, const std::string &b) const
Definition: unpack.h:27
string message() const
Get error message.
Definition: unpack.h:239
The state in which the states of packages to be unpacked are changed to status::state_half_unpacked.
Definition: unpack.h:49
state_type state() const
Get current state of the unpack operation.
Definition: unpack.h:207

Reference Manual LibPkg Version 0.6.1 (28 Jan 2015)