4 // Copyright (c) 2000-2005 Per Liden
5 // Copyright (c) 2006-2007 by CRUX team (http://crux.nu)
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.
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.
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,
33 #include <sys/types.h>
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"
53 typedef map
<string
, pkginfo_t
> packages_t
;
55 explicit pkgutil(const string
& name
);
57 virtual void run(int argc
, char** argv
) = 0;
58 virtual void print_help() const = 0;
59 void print_version() const;
63 void db_open(const string
& path
);
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
);
73 pair
<string
, pkginfo_t
> pkg_open(const string
& filename
) const;
74 void pkg_install(const string
& filename
, const set
<string
>& keep_list
, const set
<string
>& non_install_files
) const;
75 void pkg_footprint(string
& filename
) const;
76 void ldconfig() const;
85 db_lock(const string
& root
, bool exclusive
);
91 class runtime_error_with_errno
: public runtime_error
{
93 explicit runtime_error_with_errno(const string
& msg
) throw()
94 : runtime_error(msg
+ string(": ") + strerror(errno
)) {}
95 explicit runtime_error_with_errno(const string
& msg
, int e
) throw()
96 : runtime_error(msg
+ string(": ") + strerror(e
)) {}
100 void assert_argument(char** argv
, int argc
, int index
);
101 string
itos(unsigned int value
);
102 string
mtos(mode_t mode
);
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
);
110 #endif /* PKGUTIL_H */