xbps-install: -f will also overwrite pkg files.

This commit is contained in:
Juan RP 2012-11-19 20:50:58 +01:00
parent d92c87dbf3
commit 5de4fb1f0a
3 changed files with 20 additions and 8 deletions

View File

@ -118,6 +118,7 @@ main(int argc, char **argv)
flags |= XBPS_FLAG_DEBUG;
break;
case 'f':
flags |= XBPS_FLAG_FORCE_INSTALL;
reinstall = true;
break;
case 'h':

View File

@ -56,7 +56,7 @@
*/
#define XBPS_PKGINDEX_VERSION "1.5"
#define XBPS_API_VERSION "20121119-1"
#define XBPS_API_VERSION "20121119-2"
#ifndef XBPS_VERSION
#define XBPS_VERSION "UNSET"
@ -177,6 +177,14 @@
*/
#define XBPS_FLAG_DEBUG 0x00000040
/**
* @def XBPS_FLAG_FORCE_INSTALL
* Force flag used in xbps_unpack_binary_pkg(). If set its package
* files will be unpacked overwritting the current ones.
* Must be set through the xbps_handle::flags member.
*/
#define XBPS_FLAG_FORCE_INSTALL 0x00000080
/**
* @def XBPS_FETCH_CACHECONN
* Default (global) limit of cached connections used in libfetch.

View File

@ -97,13 +97,13 @@ unpack_archive(struct xbps_handle *xhp,
char *dname, *buf, *buf2, *p, *p2;
int ar_rv, rv, rv_stat, flags;
bool preserve, update, conf_file, file_exists, skip_obsoletes;
bool softreplace, skip_extract;
bool softreplace, skip_extract, force;
uid_t euid;
assert(prop_object_type(pkg_repod) == PROP_TYPE_DICTIONARY);
assert(ar != NULL);
preserve = update = conf_file = file_exists = false;
force = preserve = update = conf_file = file_exists = false;
skip_obsoletes = softreplace = false;
prop_dictionary_get_bool(pkg_repod, "preserve", &preserve);
@ -118,6 +118,9 @@ unpack_archive(struct xbps_handle *xhp,
euid = geteuid();
if (xhp->flags & XBPS_FLAG_FORCE_INSTALL)
force = true;
if (xhp->unpack_cb != NULL) {
/* initialize data for unpack cb */
memset(&xucd, 0, sizeof(xucd));
@ -282,7 +285,7 @@ unpack_archive(struct xbps_handle *xhp,
if (rv_stat == 0)
file_exists = true;
if (S_ISREG(entry_statp->st_mode)) {
if (!force && S_ISREG(entry_statp->st_mode)) {
buf = strchr(entry_pname, '.') + 1;
assert(buf != NULL);
if (file_exists) {
@ -335,7 +338,7 @@ unpack_archive(struct xbps_handle *xhp,
}
}
}
} else if (S_ISLNK(entry_statp->st_mode)) {
} else if (!force && S_ISLNK(entry_statp->st_mode)) {
/*
* Check if current link from binpkg hasn't been
* modified, otherwise extract new link.
@ -376,7 +379,7 @@ unpack_archive(struct xbps_handle *xhp,
* Check if current file mode differs from file mode
* in binpkg and apply perms if true.
*/
if (file_exists && skip_extract &&
if (!force && file_exists && skip_extract &&
(entry_statp->st_mode != st.st_mode)) {
if (chmod(entry_pname,
entry_statp->st_mode) != 0) {
@ -398,7 +401,7 @@ unpack_archive(struct xbps_handle *xhp,
* Check if current uid/gid differs from file in binpkg,
* and change permissions if true.
*/
if ((file_exists && skip_extract && (euid == 0)) &&
if ((!force && file_exists && skip_extract && (euid == 0)) &&
(((entry_statp->st_uid != st.st_uid)) ||
((entry_statp->st_gid != st.st_gid)))) {
if (chown(entry_pname,
@ -433,7 +436,7 @@ unpack_archive(struct xbps_handle *xhp,
"`%s' to `%s.old'.", entry_pname, entry_pname);
}
if (skip_extract) {
if (!force && skip_extract) {
archive_read_data_skip(ar);
continue;
}