CARDS 2.3.99
Package manager for the NuTyX GNU/Linux distribution
pkgdbh.h
1 //
2 // pkgdbh.h
3 //
4 // Copyright (c) 2000-2005 Per Liden
5 // Copyright (c) 2006-2013 by CRUX team (http://crux.nu)
6 // Copyright (c) 2013-2017 by NuTyX team (http://nutyx.org)
7 //
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
12 //
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the Free Software
20 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
21 // USA.
22 //
23 
28 #ifndef PKGDBH_H
29 #define PKGDBH_H
30 
31 #include "archive_utils.h"
32 #include "file_utils.h"
33 #include "process.h"
34 
35 #include <stdexcept>
36 #include <csignal>
37 #include <algorithm>
38 
39 #include <regex.h>
40 #include <ext/stdio_filebuf.h>
41 #include <pwd.h>
42 #include <grp.h>
43 
44 #define PKG_DB_DIR "var/lib/pkg/DB/"
45 #define PKG_FILES "/files"
46 #define PKG_META "META"
47 #define PKG_RECEPT "Pkgfile"
48 #define PKG_README "README"
49 #define PKG_PRE_INSTALL ".PRE"
50 #define PKG_POST_INSTALL ".POST"
51 
52 #define PKG_REJECTED "var/lib/pkg/rejected"
53 #define PKGADD_CONF "var/lib/pkg/pkgadd.conf"
54 #define PKGADD_CONF_MAXLINE 1024
55 
56 #define LDCONFIG "sbin/ldconfig"
57 #define LDCONFIG_CONF "etc/ld.so.conf"
58 #define LDCONFIG_CONF_ARGS "-r "
59 #define SHELL "bin/sh"
60 
61 // /usr/bin/install-info --info-dir="/usr/share/info" /usr/share/info/<file>.info"
62 #define INSTALL_INFO "usr/bin/install-info"
63 #define INSTALL_INFO_ARGS "--info-dir=usr/share/info "
64 // /usr/bin/gtk-update-icon-cache -f -t /usr/share/icons/hicolor
65 #define UPDATE_ICON "usr/bin/gtk-update-icon-cache"
66 #define UPDATE_ICON_ARGS "-f -t "
67 
68 // /usr/bin/glib-compile-schemas /usr/share/glib-2/schemas
69 #define COMPILE_SCHEMAS "usr/bin/glib-compile-schemas"
70 #define COMPILE_SCHEMAS_ARGS ""
71 
72 // /usr/bin/update-desktop-database -q /usr/share/applications
73 #define UPDATE_DESKTOP_DB "usr/bin/update-desktop-database"
74 #define UPDATE_DESKTOP_DB_ARGS "-q "
75 
76 // /usr/bin/update-mime-database usr/share/mime
77 #define UPDATE_MIME_DB "usr/bin/update-mime-database"
78 #define UPDATE_MIME_DB_ARGS "-n "
79 
80 // /usr/bin/gdk-pixbuf-query-loaders --update-cache
81 #define GDK_PIXBUF_QUERY_LOADER "usr/bin/gdk-pixbuf-query-loaders"
82 #define GDK_PIXBUF_QUERY_LOADER_ARGS "--update-cache"
83 
84 // /usr/bin/gio-querymodules /usr/lib/gio/modules
85 #define GIO_QUERYMODULES "usr/bin/gio-querymodules"
86 #define GIO_QUERYMODULES_ARGS "usr/lib/gio/modules"
87 
88 // /usr/bin/gtk-query-immodules-3.0 --update-cache
89 #define QUERY_IMMODULES_3 "usr/bin/gtk-query-immodules-3.0"
90 #define QUERY_IMMODULES_3_ARGS "--update-cache"
91 
92 // /usr/bin/gtk-query-immodules-2.0 --update-cache
93 #define QUERY_IMMODULES_2 "usr/bin/gtk-query-immodules-2.0"
94 #define QUERY_IMMODULES_2_ARGS "--update-cache"
95 
96 enum action
97 {
98 PKG_DOWNLOAD_START,
99 PKG_DOWNLOAD_RUN,
100 PKG_DOWNLOAD_END,
101 DB_OPEN_START,
102 DB_OPEN_RUN,
103 DB_OPEN_END,
104 PKG_PREINSTALL_START,
105 PKG_PREINSTALL_END,
106 PKG_INSTALL_START,
107 PKG_INSTALL_END,
108 PKG_INSTALL_RUN,
109 PKG_POSTINSTALL_START,
110 PKG_POSTINSTALL_END,
111 PKG_MOVE_META_START,
112 PKG_MOVE_META_END,
113 DB_ADD_PKG_START,
114 DB_ADD_PKG_END,
115 LDCONFIG_START,
116 LDCONFIG_END,
117 RM_PKG_FILES_START,
118 RM_PKG_FILES_RUN,
119 RM_PKG_FILES_END
120 };
121 
122 struct pkginfo_t {
123  std::string base;
124  std::string group;
125  std::string collection;
126  std::string description;
127  std::string signature;
128  time_t build; // date of build
129  std::string version;
130  int release;
131  std::string url;
132  std::string contributors;
133  std::string packager;
134  std::string maintainer;
135  time_t install; // date of last installation
136  std::string arch;
137  int size;
138  std::set< std::pair<std::string,time_t> > dependencies;
139  std::set<std::string> alias;
140  std::set<std::string> files;
141 };
142 typedef std::map<std::string, pkginfo_t> packages_t;
143 typedef std::map<std::string, std::string> alias_t;
144 
145 enum rule_event_t {
146  LDCONF,
147  UPGRADE,
148  INSTALL,
149  INFO,
150  ICONS,
151  SCHEMAS,
152  DESKTOP_DB,
153  MIME_DB,
154  QUERY_PIXBUF,
155  GIO_QUERY,
156  QUERY_IMOD3,
157  QUERY_IMOD2
158 };
159 
160 struct rule_t {
161  rule_event_t event;
162  std::string pattern;
163  bool action;
164 };
165 
166 class Pkgdbh {
167 public:
168 
169  explicit Pkgdbh(const std::string& name);
170  virtual ~Pkgdbh();
171 
172  /* Following methods can be redefined in derivated class */
173  virtual void parseArguments(int argc, char** argv);
174  virtual void run(int argc, char** argv) {};
175  virtual void run() {};
176 
177  virtual void printHelp() const {};
178 
179  virtual void progressInfo() const;
180  virtual void treatErrors(const std::string& s) const;
181 
182 
183  void print_version() const;
184  int getNumberOfPackages();
185  std::set<std::string> getListOfPackageName();
186  bool checkPackageNameExist(const std::string& name) const;
187 
188 protected:
189  // Database
190 
191  std::set<std::string> getFilesOfPackage(const std::string& packageName);
192  int getListOfPackageNames(const std::string& path);
193  std::pair<std::string, pkginfo_t> getInfosPackage(const std::string& packageName);
194  void buildSimpleDatabase();
195  void buildCompleteDatabase(const bool& silent);
196  void buildDatabase(const bool& progress,
197  const bool& simple,
198  const bool& all,
199  const bool& files,
200  const std::string& packageName);
201 
202 
203  void addPackageFilesRefsToDB(const std::string& name,
204  const pkginfo_t& info);
205 
206  bool checkPackageNameUptodate(const std::pair<std::string,
207  pkginfo_t>& archiveName);
208  bool checkPackageNameBuildDateSame(const std::pair<std::string,
209  time_t>& dependencieNameBuild);
210 
211  /*
212  * Remove the physical files after followings some rules
213  */
214  void removePackageFiles(const std::string& name);
215  void removePackageFiles(const std::string& name,
216  const std::set<std::string>& keep_list);
217 
218  /*
219  * Remove meta data about the removed package
220  */
221  void removePackageFilesRefsFromDB(const std::string& name);
222  void removePackageFilesRefsFromDB(std::set<std::string> files,
223  const std::set<std::string>& keep_list);
224  std::set<std::string> getConflictsFilesList(const std::string& name,
225  const pkginfo_t& info);
226 
227  // Tar.gz
228  std::pair<std::string, pkginfo_t> openArchivePackage(const std::string& filename);
229  std::set< std::pair<std::string, time_t> > getPackageDependencies(const std::string& filename);
230  void extractAndRunPREfromPackage(const std::string& filename);
231  void installArchivePackage(const std::string& filename,
232  const std::set<std::string>& keep_list,
233  const std::set<std::string>& non_install_files);
234 
235  /*
236  * The folder holding the meta datas is going to be create here
237  */
238  void moveMetaFilesPackage(const std::string& name, pkginfo_t& info);
239 
240 
241  void readRulesFile();
242  void getInstallRulesList(const std::vector<rule_t>& rules,
243  rule_event_t event, std::vector<rule_t>& found) const;
244  bool checkRuleAppliesToFile(const rule_t& rule,
245  const std::string& file);
246 
247  void getFootprintPackage(std::string& filename);
248 
249  std::string m_packageArchiveName;
250  std::string m_packageName;
251  std::string m_packageArchiveVersion;
252  std::string m_packageArchiveRelease;
253  std::string m_packageArchiveCollection;
254  std::string m_packageVersion;
255  std::string m_packageRelease;
256  std::string m_packageCollection;
257  std::string m_utilName;
258  std::string m_root;
259  std::string m_build;
260  std::vector<rule_t> m_actionRules;
261  std::set< std::pair<std::string, int> > m_postInstallList;
262  alias_t m_listOfAlias;
263 
264  packages_t m_listOfInstPackages;
265  packages_t m_listOfDepotPackages;
266 
267  action m_actualAction;
268  error m_actualError;
269 
270 private:
271 
272  void runLastPostInstall();
273 
274  std::set<std::string> m_runtimeLibrariesList;
275  std::set<std::string> m_filesList;
276  std::set<std::string> m_packageNamesList;
277  unsigned int m_filesNumber;
278  unsigned int m_installedFilesNumber;
279 
280 
281  bool m_DB_Empty;
282  bool m_miniDB_Empty;
283 };
284 
285 class Db_lock {
286 public:
287  Db_lock(const std::string& m_root, bool exclusive);
288  ~Db_lock();
289 
290 private:
291  DIR* m_dir;
292  struct sigaction m_sa;
293 };
294 
295 // Utility functions
296 void assertArgument(char** argv, int argc, int index);
297 void rotatingCursor();
298 #endif /* PKGDBH_H */
299 // vim:set ts=2 :
Definition: libcards.h:1320
Definition: libcards.h:1358
Definition: libcards.h:1483
Definition: libcards.h:1364