Commit | Line | Data |
---|---|---|
9ac667e6 SR |
1 | // |
2 | // pkgutils | |
3 | // | |
4 | // Copyright (c) 2000-2005 Per Liden | |
5 | // | |
6 | // This program is free software; you can redistribute it and/or modify | |
7 | // it under the terms of the GNU General Public License as published by | |
8 | // the Free Software Foundation; either version 2 of the License, or | |
9 | // (at your option) any later version. | |
10 | // | |
11 | // This program is distributed in the hope that it will be useful, | |
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | // GNU General Public License for more details. | |
15 | // | |
16 | // You should have received a copy of the GNU General Public License | |
17 | // along with this program; if not, write to the Free Software | |
18 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
19 | // USA. | |
20 | // | |
21 | ||
22 | #ifndef PKGUTIL_H | |
23 | #define PKGUTIL_H | |
24 | ||
25 | #include <string> | |
26 | #include <set> | |
27 | #include <map> | |
28 | #include <iostream> | |
29 | #include <stdexcept> | |
30 | #include <cerrno> | |
31 | #include <cstring> | |
32 | #include <sys/types.h> | |
33 | #include <dirent.h> | |
34 | ||
35 | #define PKG_EXT ".pkg.tar.gz" | |
36 | #define PKG_DIR "var/lib/pkg" | |
37 | #define PKG_DB "var/lib/pkg/db" | |
38 | #define PKG_REJECTED "var/lib/pkg/rejected" | |
39 | #define VERSION_DELIM '#' | |
40 | #define LDCONFIG "/sbin/ldconfig" | |
41 | #define LDCONFIG_CONF "/etc/ld.so.conf" | |
42 | ||
43 | using namespace std; | |
44 | ||
45 | class pkgutil { | |
46 | public: | |
47 | struct pkginfo_t { | |
48 | string version; | |
49 | set<string> files; | |
50 | }; | |
51 | ||
52 | typedef map<string, pkginfo_t> packages_t; | |
53 | ||
54 | explicit pkgutil(const string& name); | |
55 | virtual ~pkgutil() {} | |
56 | virtual void run(int argc, char** argv) = 0; | |
57 | virtual void print_help() const = 0; | |
58 | void print_version() const; | |
59 | ||
60 | protected: | |
61 | // Database | |
62 | void db_open(const string& path); | |
63 | void db_commit(); | |
64 | void db_add_pkg(const string& name, const pkginfo_t& info); | |
65 | bool db_find_pkg(const string& name); | |
66 | void db_rm_pkg(const string& name); | |
67 | void db_rm_pkg(const string& name, const set<string>& keep_list); | |
68 | void db_rm_files(set<string> files, const set<string>& keep_list); | |
69 | set<string> db_find_conflicts(const string& name, const pkginfo_t& info); | |
70 | ||
71 | // Tar.gz | |
72 | pair<string, pkginfo_t> pkg_open(const string& filename) const; | |
73 | void pkg_install(const string& filename, const set<string>& keep_list) const; | |
74 | void pkg_footprint(string& filename) const; | |
75 | void ldconfig() const; | |
76 | ||
77 | string utilname; | |
78 | packages_t packages; | |
79 | string root; | |
80 | }; | |
81 | ||
82 | class db_lock { | |
83 | public: | |
84 | db_lock(const string& root, bool exclusive); | |
85 | ~db_lock(); | |
86 | private: | |
87 | DIR* dir; | |
88 | }; | |
89 | ||
90 | class runtime_error_with_errno : public runtime_error { | |
91 | public: | |
92 | explicit runtime_error_with_errno(const string& msg) throw() | |
93 | : runtime_error(msg + string(": ") + strerror(errno)) {} | |
94 | }; | |
95 | ||
96 | // Utility functions | |
97 | void assert_argument(char** argv, int argc, int index); | |
98 | string itos(unsigned int value); | |
99 | string mtos(mode_t mode); | |
100 | int unistd_gzopen(char* pathname, int flags, mode_t mode); | |
101 | string trim_filename(const string& filename); | |
102 | bool file_exists(const string& filename); | |
103 | bool file_empty(const string& filename); | |
104 | bool file_equal(const string& file1, const string& file2); | |
105 | bool permissions_equal(const string& file1, const string& file2); | |
106 | void file_remove(const string& basedir, const string& filename); | |
107 | ||
108 | #endif /* PKGUTIL_H */ |