CARDS 2.4.87
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-2018 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 
65 // /usr/bin/gtk-update-icon-cache -f -t /usr/share/icons/hicolor
66 #define UPDATE_ICON "usr/bin/gtk-update-icon-cache"
67 #define UPDATE_ICON_ARGS "-f -t "
68 
69 // /usr/bin/glib-compile-schemas /usr/share/glib-2/schemas
70 #define COMPILE_SCHEMAS "usr/bin/glib-compile-schemas"
71 #define COMPILE_SCHEMAS_ARGS ""
72 
73 // /usr/bin/update-desktop-database -q /usr/share/applications
74 #define UPDATE_DESKTOP_DB "usr/bin/update-desktop-database"
75 #define UPDATE_DESKTOP_DB_ARGS "-q "
76 
77 // /usr/bin/update-mime-database usr/share/mime
78 #define UPDATE_MIME_DB "usr/bin/update-mime-database"
79 #define UPDATE_MIME_DB_ARGS "-n "
80 
81 // /usr/bin/gdk-pixbuf-query-loaders --update-cache
82 #define GDK_PIXBUF_QUERY_LOADER "usr/bin/gdk-pixbuf-query-loaders"
83 #define GDK_PIXBUF_QUERY_LOADER_ARGS "--update-cache"
84 
85 // /usr/bin/gio-querymodules /usr/lib/gio/modules
86 #define GIO_QUERYMODULES "usr/bin/gio-querymodules"
87 #define GIO_QUERYMODULES_ARGS "usr/lib/gio/modules"
88 
89 // /usr/bin/gtk-query-immodules-3.0 --update-cache
90 #define QUERY_IMMODULES_3 "usr/bin/gtk-query-immodules-3.0"
91 #define QUERY_IMMODULES_3_ARGS "--update-cache"
92 
93 // /usr/bin/gtk-query-immodules-2.0 --update-cache
94 #define QUERY_IMMODULES_2 "usr/bin/gtk-query-immodules-2.0"
95 #define QUERY_IMMODULES_2_ARGS "--update-cache"
96 
97 // /usr/bin/mkfontdir /usr/share/fonts/<dir>/
98 #define MKFONTDIR "usr/bin/mkfontdir"
99 #define MKFONTDIR_ARGS ""
100 
101 // /usr/bin/mkfontscale /usr/share/fonts/<dir>/
102 #define MKFONTSCALE "usr/bin/mkfontscale"
103 #define MKFONTSCALE_ARGS ""
104 
105 // /usr/bin/fc-cache /usr/share/fonts/<dir>/
106 #define FC_CACHE "usr/bin/fc-cache"
107 #define FC_CACHE_ARGS ""
108 
109 enum action
110 {
111 PKG_DOWNLOAD_START,
112 PKG_DOWNLOAD_RUN,
113 PKG_DOWNLOAD_END,
114 DB_OPEN_START,
115 DB_OPEN_RUN,
116 DB_OPEN_END,
117 PKG_PREINSTALL_START,
118 PKG_PREINSTALL_END,
119 PKG_INSTALL_START,
120 PKG_INSTALL_END,
121 PKG_INSTALL_RUN,
122 PKG_POSTINSTALL_START,
123 PKG_POSTINSTALL_END,
124 PKG_MOVE_META_START,
125 PKG_MOVE_META_END,
126 DB_ADD_PKG_START,
127 DB_ADD_PKG_END,
128 LDCONFIG_START,
129 LDCONFIG_END,
130 RM_PKG_FILES_START,
131 RM_PKG_FILES_RUN,
132 RM_PKG_FILES_END
133 };
134 
135 struct pkginfo_t {
136  std::string base;
137  std::string group;
138  std::string collection;
139  std::string description;
140  std::string signature;
141  time_t build; // date of build
142  std::string version;
143  int release;
144  std::string url;
145  std::string contributors;
146  std::string packager;
147  std::string maintainer;
148  time_t install; // date of last installation
149  std::string arch;
150  int size;
151  std::set< std::pair<std::string,time_t> > dependencies;
152  std::set<std::string> alias;
153  std::set<std::string> files;
154 };
155 typedef std::map<std::string, pkginfo_t> packages_t;
156 typedef std::map<std::string, std::string> alias_t;
157 
158 enum rule_event_t {
159  LDCONF,
160  UPGRADE,
161  INSTALL,
162  INFO,
163  ICONS,
164  FONTS,
165  SCHEMAS,
166  DESKTOP_DB,
167  MIME_DB,
168  QUERY_PIXBUF,
169  GIO_QUERY,
170  QUERY_IMOD3,
171  QUERY_IMOD2
172 };
173 
174 struct rule_t {
175  rule_event_t event;
176  std::string pattern;
177  bool action;
178 };
179 
180 class Pkgdbh {
181 public:
182 
183  explicit Pkgdbh(const std::string& name);
184  virtual ~Pkgdbh();
185 
186  /* Following methods can be redefined in derivated class */
187  virtual void parseArguments(int argc, char** argv);
188  virtual void run(int argc, char** argv) {};
189  virtual void run() {};
190 
191  virtual void printHelp() const {};
192 
193  virtual void progressInfo();
194  virtual void treatErrors(const std::string& s) const;
195 
196 
197  void print_version() const;
198  int getNumberOfPackages();
199  std::set<std::string> getListOfPackageName();
200  bool checkPackageNameExist(const std::string& name) const;
201  unsigned int getFilesNumber();
202  unsigned int getInstalledFilesNumber();
203  std::set<std::string> getFilesList();
204 
205 protected:
206  // Database
207 
208  std::set<std::string> getFilesOfPackage(const std::string& packageName);
209  int getListOfPackageNames(const std::string& path);
210  std::pair<std::string, pkginfo_t> getInfosPackage(const std::string& packageName);
211  void buildSimpleDatabase();
212  void buildCompleteDatabase(const bool& silent);
213  void buildDatabase(const bool& progress,
214  const bool& simple,
215  const bool& all,
216  const bool& files,
217  const std::string& packageName);
218 
219 
220  void addPackageFilesRefsToDB(const std::string& name,
221  const pkginfo_t& info);
222 
223  bool checkPackageNameUptodate(const std::pair<std::string,
224  pkginfo_t>& archiveName);
225  bool checkPackageNameBuildDateSame(const std::pair<std::string,
226  time_t>& dependencieNameBuild);
227 
228  /*
229  * Remove the physical files after followings some rules
230  */
231  void removePackageFiles(const std::string& name);
232  void removePackageFiles(const std::string& name,
233  const std::set<std::string>& keep_list);
234 
235  /*
236  * Remove meta data about the removed package
237  */
238  void removePackageFilesRefsFromDB(const std::string& name);
239  void removePackageFilesRefsFromDB(std::set<std::string> files,
240  const std::set<std::string>& keep_list);
241  std::set<std::string> getConflictsFilesList(const std::string& name,
242  const pkginfo_t& info);
243 
244  // Tar.gz
245  std::pair<std::string, pkginfo_t> openArchivePackage(const std::string& filename);
246  std::set< std::pair<std::string, time_t> > getPackageDependencies(const std::string& filename);
247  void extractAndRunPREfromPackage(const std::string& filename);
248  void installArchivePackage(const std::string& filename,
249  const std::set<std::string>& keep_list,
250  const std::set<std::string>& non_install_files);
251 
252  /*
253  * The folder holding the meta datas is going to be create here
254  */
255  void moveMetaFilesPackage(const std::string& name, pkginfo_t& info);
256 
257 
258  void readRulesFile();
259  void getInstallRulesList(const std::vector<rule_t>& rules,
260  rule_event_t event, std::vector<rule_t>& found) const;
261  bool checkRuleAppliesToFile(const rule_t& rule,
262  const std::string& file);
263 
264  void getFootprintPackage(std::string& filename);
265 
266  std::string m_packageArchiveName;
267  std::string m_packageName;
268  std::string m_packageArchiveVersion;
269  std::string m_packageArchiveRelease;
270  std::string m_packageArchiveCollection;
271  std::string m_packageVersion;
272  std::string m_packageRelease;
273  std::string m_packageCollection;
274  std::string m_utilName;
275  std::string m_root;
276  std::string m_build;
277  std::vector<rule_t> m_actionRules;
278  std::set< std::pair<std::string, int> > m_postInstallList;
279  alias_t m_listOfAlias;
280 
281  packages_t m_listOfInstPackages;
282  packages_t m_listOfDepotPackages;
283 
284  action m_actualAction;
285  error m_actualError;
286 
287 private:
288 
289  void runLastPostInstall();
290 
291  std::set<std::string> m_runtimeLibrariesList;
292  std::set<std::string> m_filesList;
293  std::set<std::string> m_packageNamesList;
294  unsigned int m_filesNumber;
295  unsigned int m_installedFilesNumber;
296 
297 
298  bool m_DB_Empty;
299  bool m_miniDB_Empty;
300 };
301 
302 class Db_lock {
303 public:
304  Db_lock(const std::string& m_root, bool exclusive);
305  ~Db_lock();
306 
307 private:
308  DIR* m_dir;
309  struct sigaction m_sa;
310 };
311 
312 // Utility functions
313 void assertArgument(char** argv, int argc, int index);
314 void rotatingCursor();
315 #endif /* PKGDBH_H */
316 // vim:set ts=2 :
Definition: libcards.h:1450
Definition: libcards.h:1489
void buildSimpleDatabase()
Definition: pkgdbh.cxx:479
void buildCompleteDatabase(const bool &silent)
Definition: pkgdbh.cxx:538
void buildDatabase(const bool &progress, const bool &simple, const bool &all, const bool &files, const std::string &packageName)
Definition: pkgdbh.cxx:363
Definition: libcards.h:1617
Definition: libcards.h:1495