configuration: add keepconf option

Add configuration option keepconf that stops xbps from overwriting
unchanged configuration files. If keepconf=true, xbps will store the new
configuration as <name>.new-<version> instead of overwriting unchanged
configuration files.
This commit is contained in:
Andreas Kempe
2020-01-24 23:09:12 +01:00
committed by Juan RP
parent 71a594f681
commit 02c9cb11c4
7 changed files with 115 additions and 5 deletions

View File

@ -171,6 +171,7 @@ enum {
KEY_ROOTDIR,
KEY_SYSLOG,
KEY_VIRTUALPKG,
KEY_KEEPCONF,
};
static const struct key {
@ -189,6 +190,7 @@ static const struct key {
{ "rootdir", 7, KEY_ROOTDIR },
{ "syslog", 6, KEY_SYSLOG },
{ "virtualpkg", 10, KEY_VIRTUALPKG },
{ "keepconf", 8, KEY_KEEPCONF },
};
static int
@ -356,6 +358,15 @@ parse_file(struct xbps_handle *xhp, const char *path, bool nested)
case KEY_PRESERVE:
store_preserved_file(xhp, val);
break;
case KEY_KEEPCONF:
if (strcasecmp(val, "true") == 0) {
xhp->flags |= XBPS_FLAG_KEEP_CONFIG;
xbps_dbg_printf(xhp, "%s: config preservation enabled\n", path);
} else {
xhp->flags &= ~XBPS_FLAG_KEEP_CONFIG;
xbps_dbg_printf(xhp, "%s: config preservation disabled\n", path);
}
break;
case KEY_BESTMATCHING:
if (strcasecmp(val, "true") == 0) {
xhp->flags |= XBPS_FLAG_BESTMATCH;

View File

@ -181,6 +181,7 @@ xbps_init(struct xbps_handle *xhp)
xbps_dbg_printf(xhp, "sysconfdir=%s\n", xhp->sysconfdir);
xbps_dbg_printf(xhp, "syslog=%s\n", xhp->flags & XBPS_FLAG_DISABLE_SYSLOG ? "false" : "true");
xbps_dbg_printf(xhp, "bestmatching=%s\n", xhp->flags & XBPS_FLAG_BESTMATCH ? "true" : "false");
xbps_dbg_printf(xhp, "keepconf=%s\n", xhp->flags & XBPS_FLAG_KEEP_CONFIG ? "true" : "false");
xbps_dbg_printf(xhp, "Architecture: %s\n", xhp->native_arch);
xbps_dbg_printf(xhp, "Target Architecture: %s\n", xhp->target_arch);

View File

@ -170,11 +170,13 @@ xbps_entry_install_conf_file(struct xbps_handle *xhp,
/*
* Orig = X, Curr = X, New = Y
*
* Install new file (installed file hasn't been modified).
* Install new file (installed file hasn't been modified) if
* configuration option keepconfig is NOT set.
*/
} else if ((strcmp(sha256_orig, sha256_cur) == 0) &&
(strcmp(sha256_orig, sha256_new)) &&
(strcmp(sha256_cur, sha256_new))) {
(strcmp(sha256_cur, sha256_new)) &&
(!(xhp->flags & XBPS_FLAG_KEEP_CONFIG))) {
xbps_set_cb_state(xhp, XBPS_STATE_CONFIG_FILE,
0, pkgver,
"Updating configuration file `%s' provided "
@ -212,12 +214,15 @@ xbps_entry_install_conf_file(struct xbps_handle *xhp,
break;
/*
* Orig = X, Curr = Y, New = Z
* or
* Orig = X, Curr = X, New = Y if keepconf is set
*
* Install new file as <file>.new-<version>
*/
} else if ((strcmp(sha256_orig, sha256_cur)) &&
} else if (((strcmp(sha256_orig, sha256_cur)) &&
(strcmp(sha256_cur, sha256_new)) &&
(strcmp(sha256_orig, sha256_new))) {
(strcmp(sha256_orig, sha256_new))) ||
(xhp->flags & XBPS_FLAG_KEEP_CONFIG)) {
version = xbps_pkg_version(pkgver);
assert(version);
snprintf(buf, sizeof(buf), ".%s.new-%s", cffile, version);