From 5de4fb1f0ac4a9d279ac2b8e4b03c2c4371c3c65 Mon Sep 17 00:00:00 2001 From: Juan RP Date: Mon, 19 Nov 2012 20:50:58 +0100 Subject: [PATCH] xbps-install: -f will also overwrite pkg files. --- bin/xbps-install/main.c | 1 + include/xbps_api.h.in | 10 +++++++++- lib/package_unpack.c | 17 ++++++++++------- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/bin/xbps-install/main.c b/bin/xbps-install/main.c index 9c0e65bf..d9cc9a00 100644 --- a/bin/xbps-install/main.c +++ b/bin/xbps-install/main.c @@ -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': diff --git a/include/xbps_api.h.in b/include/xbps_api.h.in index 0503cb5c..aa140ab7 100644 --- a/include/xbps_api.h.in +++ b/include/xbps_api.h.in @@ -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. diff --git a/lib/package_unpack.c b/lib/package_unpack.c index 9b5d5b96..fc351c30 100644 --- a/lib/package_unpack.c +++ b/lib/package_unpack.c @@ -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; }