Commit | Line | Data |
---|---|---|
9ac667e6 SR |
1 | // |
2 | // pkgutils | |
3 | // | |
4 | // Copyright (c) 2000-2005 Per Liden | |
6fe55c25 | 5 | // Copyright (c) 2006-2007 by CRUX team (http://crux.nu) |
9ac667e6 SR |
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 PKGUTIL_H | |
24 | #define PKGUTIL_H | |
25 | ||
26 | #include <string> | |
27 | #include <set> | |
28 | #include <map> | |
29 | #include <iostream> | |
30 | #include <stdexcept> | |
31 | #include <cerrno> | |
32 | #include <cstring> | |
33 | #include <sys/types.h> | |
34 | #include <dirent.h> | |
35 | ||
36 | #define PKG_EXT ".pkg.tar.gz" | |
37 | #define PKG_DIR "var/lib/pkg" | |
38 | #define PKG_DB "var/lib/pkg/db" | |
39 | #define PKG_REJECTED "var/lib/pkg/rejected" | |
40 | #define VERSION_DELIM '#' | |
41 | #define LDCONFIG "/sbin/ldconfig" | |
42 | #define LDCONFIG_CONF "/etc/ld.so.conf" | |
43 | ||
44 | using namespace std; | |
45 | ||
46 | class pkgutil { | |
47 | public: | |
48 | struct pkginfo_t { | |
49 | string version; | |
50 | set<string> files; | |
51 | }; | |
52 | ||
53 | typedef map<string, pkginfo_t> packages_t; | |
54 | ||
55 | explicit pkgutil(const string& name); | |
56 | virtual ~pkgutil() {} | |
57 | virtual void run(int argc, char** argv) = 0; | |
58 | virtual void print_help() const = 0; | |
59 | void print_version() const; | |
60 | ||
61 | protected: | |
62 | // Database | |
63 | void db_open(const string& path); | |
64 | void db_commit(); | |
65 | void db_add_pkg(const string& name, const pkginfo_t& info); | |
66 | bool db_find_pkg(const string& name); | |
67 | void db_rm_pkg(const string& name); | |
68 | void db_rm_pkg(const string& name, const set<string>& keep_list); | |
69 | void db_rm_files(set<string> files, const set<string>& keep_list); | |
70 | set<string> db_find_conflicts(const string& name, const pkginfo_t& info); | |
71 | ||
72 | // Tar.gz | |
73 | pair<string, pkginfo_t> pkg_open(const string& filename) const; | |
3e5b7ed9 | 74 | void pkg_install(const string& filename, const set<string>& keep_list, const set<string>& non_install_files) const; |
9ac667e6 SR |
75 | void pkg_footprint(string& filename) const; |
76 | void ldconfig() const; | |
77 | ||
78 | string utilname; | |
79 | packages_t packages; | |
80 | string root; | |
81 | }; | |
82 | ||
83 | class db_lock { | |
84 | public: | |
85 | db_lock(const string& root, bool exclusive); | |
86 | ~db_lock(); | |
87 | private: | |
88 | DIR* dir; | |
89 | }; | |
90 | ||
91 | class runtime_error_with_errno : public runtime_error { | |
92 | public: | |
93 | explicit runtime_error_with_errno(const string& msg) throw() | |
94 | : runtime_error(msg + string(": ") + strerror(errno)) {} | |
25f9975c TS |
95 | explicit runtime_error_with_errno(const string& msg, int e) throw() |
96 | : runtime_error(msg + string(": ") + strerror(e)) {} | |
9ac667e6 SR |
97 | }; |
98 | ||
99 | // Utility functions | |
100 | void assert_argument(char** argv, int argc, int index); | |
101 | string itos(unsigned int value); | |
102 | string mtos(mode_t mode); | |
9ac667e6 SR |
103 | string trim_filename(const string& filename); |
104 | bool file_exists(const string& filename); | |
105 | bool file_empty(const string& filename); | |
106 | bool file_equal(const string& file1, const string& file2); | |
107 | bool permissions_equal(const string& file1, const string& file2); | |
108 | void file_remove(const string& basedir, const string& filename); | |
109 | ||
110 | #endif /* PKGUTIL_H */ |