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