CARDS 2.4.87
Package manager for the NuTyX GNU/Linux distribution
archive_utils.h
1 //
2 // archive_utils.h
3 //
4 // Copyright (c) 2002 by Johannes Winkelmann
5 // Copyright (c) 2013-2017 by NuTyX team (http://nutyx.org)
6 //
7 // This program is free software; you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by
9 // the Free Software Foundation; either version 2 of the License, or
10 // (at your option) any later version.
11 //
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
20 // USA.
21 //
22 
23 #ifndef ARCHIVEUTILS_H
24 #define ARCHIVEUTILS_H
25 
26 #include "string_utils.h"
27 
28 #include <archive.h>
29 #include <archive_entry.h>
30 
31 
32 #if ARCHIVE_VERSION_NUMBER >= 3000000
33 #define INIT_ARCHIVE(ar) \
34  archive_read_support_filter_gzip((ar)); \
35  archive_read_support_filter_bzip2((ar)); \
36  archive_read_support_filter_xz((ar)); \
37  archive_read_support_format_tar((ar))
38 #define FREE_ARCHIVE(ar) \
39  archive_read_free((ar))
40 #else
41 #define INIT_ARCHIVE(ar) \
42  archive_read_support_compression_gzip((ar)); \
43  archive_read_support_compression_bzip2((ar)); \
44  archive_read_support_compression_xz((ar)); \
45  archive_read_support_format_tar((ar))
46 #define FREE_ARCHIVE(ar) \
47  archive_read_finish((ar))
48 #endif
49 
50 #define DEFAULT_BYTES_PER_BLOCK (20 * 512)
51 #define METAFILE ".META"
52 #define INFOFILE ".INFO"
53 #define MTREEFILE ".MTREE"
54 
55 enum archive_error
56 {
57 CANNOT_OPEN_ARCHIVE,
58 CANNOT_READ_ARCHIVE,
59 CANNOT_FIND_META_FILE,
60 CANNOT_FIND_MTREE_FILE,
61 CANNOT_FIND_NAME,
62 CANNOT_FIND_ARCH,
63 EMPTY_ARCHIVE
64 };
65 
66 
68 {
69  public:
70 
71 
72  ArchiveUtils(const std::string& fileName);
73  virtual ~ArchiveUtils();
74 
75  virtual void treatErrors(const std::string& s) const;
76 
77  void printDeps(); // Print Out the dependencies
78  void printMeta(); // Print Out the .META file
79  void printInfo(); // the .INFO file
80  void list(); // list the files to stdio
81 
82 
83  unsigned int long size(); // Numbers of files in the archive
84  std::set<std::string> setofFiles(); // return a order set of string
85  std::set<std::string> listofDependencies(); // return an order set of dependencies
86  std::set<std::string> listofAlias(); // return the alias list
87  std::set<std::pair<std::string,time_t> > listofDependenciesBuildDate(); // return an order set of dependencies,BuildDate
88  std::string arch(); // return the arch of the package
89  std::string version(); // return the version of the package
90  int release(); // return the release of the package
91  std::string description();// return the description of the package
92  std::string url(); // return the url of the package
93  std::string contributors(); // return the Contributor(s) of the package
94  std::string maintainer(); // return the Maintainer(s) of the package
95  std::string collection(); // return the collection of the package
96  std::string packager(); // return the Packager(s) of the package
97  std::string builddate(); // return the date like Mon Mar 24 10:16:00 2014
98  std::string name(); // return the name of the package
99  std::string namebuildn(); // return the name + epochvalue
100  std::string epochBuildDate(); // return the epochvalue in string format
101  time_t buildn(); // return the epoch value
102 
103  private:
104 
105  std::string getPackageName();
106  std::string getPackageArch();
107  std::vector<std::string> extractFileContent(const char * fileName);
108  void getRunTimeDependencies();
109  void getRunTimeDependenciesEpoch();
110  void getAliasList();
111 
112  unsigned int long m_size;
113 
114  std::vector<std::string> m_contentMtree;
115  std::vector<std::string> m_contentMeta;
116  std::vector<std::string> m_contentInfo;
117 
118  std::set<std::string> m_rtDependenciesList;
119  std::set<std::pair<std::string,time_t> > m_rtDependenciesEpochList;
120  std::string m_fileName;
121  std::string m_packageName;
122  std::string m_packageArch;
123  std::set<std::string> m_filesList;
124  std::set<std::string> m_aliasList;
125 
126  archive_error m_actualError;
127 };
128 
129 int openArchive(const char *fileName);
130 
131 #endif /* ARCHIVEUTILS_H */
132 // vim:set ts=2 :
Definition: archive_utils.h:67