Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Make BACKUP_LIBRARIES create one backup package per source package
Mark Johnston committed 6 months ago
commit 72aedda03227be3406fe016dda2dd84474be1ac3
parent 1d39986
3 files changed +50 -29
modified docs/pkg.conf.5
@@ -122,13 +122,17 @@ Default: NO.
.It Cm BACKUP_LIBRARIES: boolean
If set to
.Sy true
-
and if an upgrade will remove a library, then
+
and if an upgrade will remove a library (typically due to the library version
+
number having been bumped), then
.Xr pkg 8
-
will backup the library to the path defined by
+
will back up the library to the path defined by
.Cm BACKUP_LIBRARY_PATH .
-
An initial backup will create the 
-
.Qq compat-libraries
-
package. The package version will be bumped whenever an additional library is backed up.
+
A package containing the backed up library will be created.
+
This package is named after the original package containing the library, with
+
the suffix
+
.Ql -backup-libraries
+
appended.
+
The package version will be bumped whenever an additional library is backed up.
Default: NO.
.It Cm BACKUP_LIBRARY_PATH: string
Path for library backups.
modified libpkg/backup_lib.c
@@ -32,32 +32,37 @@
#include "private/pkg.h"

static int
-
register_backup(struct pkgdb *db, int fd, const char *path)
+
register_backup(struct pkgdb *db, struct pkg *orig, int fd, const char *path)
{
	struct pkgdb_it *it;
	struct pkg *pkg = NULL;
	time_t t;
	char buf[BUFSIZ];
-
	char *sum;
+
	char *lpath, *name, *sum;
	struct pkg_file *f;
-
	char *lpath;
	struct stat st;
	pkghash_entry *e;
	int retcode;

-
	sum = pkg_checksum_generate_fileat(fd, RELATIVE_PATH(path), PKG_HASH_TYPE_SHA256_HEX);
+
	sum = pkg_checksum_generate_fileat(fd, RELATIVE_PATH(path),
+
	    PKG_HASH_TYPE_SHA256_HEX);

-
	it = pkgdb_query(db, "compat-libraries", MATCH_EXACT);
+
	(void)xasprintf(&name, "%s-backup-libraries", orig->name);
+

+
	it = pkgdb_query(db, name, MATCH_EXACT);
	if (it != NULL) {
		pkgdb_it_next(it, &pkg, PKG_LOAD_BASIC|PKG_LOAD_FILES);
		pkgdb_it_free(it);
	}
	if (pkg == NULL) {
+
		char *origin;
+

		if (pkg_new(&pkg, PKG_FILE) != EPKG_OK) {
			return (EPKG_FATAL);
		}
-
		pkg->name = xstrdup("compat-libraries");
-
		pkg->origin = xstrdup("compat/libraries");
+
		pkg->name = name;
+
		(void)xasprintf(&origin, "%s-backup", orig->origin);
+
		pkg->origin = origin;
		pkg->comment = xstrdup(
		    "Compatibility libraries saved during package upgrade");
		pkg->desc = xstrdup(
@@ -65,11 +70,11 @@ register_backup(struct pkgdb *db, int fd, const char *path)
		pkg->maintainer = xstrdup("root@localhost");
		pkg->www = xstrdup("N/A");
		pkg->prefix = xstrdup("/");
-
		pkg->abi = pkg_abi_to_string(&ctx.abi);
+
		pkg->abi = xstrdup(orig->abi);
+
	} else {
+
		free(name);
+
		name = NULL;
	}
-
	free(pkg->version);
-
	t = time(NULL);
-
	strftime(buf, sizeof(buf), "%Y%m%d%H%M%S", localtime(&t));
	if ((e = pkghash_get(pkg->filehash, path)) != NULL) {
		DL_DELETE(pkg->files, (struct pkg_file *)e->value);
		pkg_file_free(e->value);
@@ -78,17 +83,23 @@ register_backup(struct pkgdb *db, int fd, const char *path)
	xasprintf(&lpath, "%s/%s", ctx.backup_library_path, path);
	pkg_addfile(pkg, lpath, sum, false);
	free(lpath);
+

+
	t = time(NULL);
+
	strftime(buf, sizeof(buf), "%Y%m%d%H%M%S", localtime(&t));
+
	free(pkg->version);
	pkg->version = xstrdup(buf);
+

	pkg_analyse_files(NULL, pkg, ctx.pkg_rootdir);
	pkg_open_root_fd(pkg);
	f = NULL;
	while (pkg_files(pkg, &f) == EPKG_OK) {
-
		if (fstatat(pkg->rootfd, RELATIVE_PATH(f->path), &st, AT_SYMLINK_NOFOLLOW) != -1)
+
		if (fstatat(pkg->rootfd, RELATIVE_PATH(f->path), &st,
+
		    AT_SYMLINK_NOFOLLOW) != -1)
			pkg->flatsize += st.st_size;
	}
	retcode = pkgdb_register_pkg(db, pkg, 1, "backuplib");
	if (retcode == EPKG_OK)
-
		pkgdb_register_finale(db, EPKG_OK, "backuplib");
+
		retcode = pkgdb_register_finale(db, EPKG_OK, "backuplib");
	return (retcode);
}

@@ -146,7 +157,7 @@ backup_library(struct pkgdb *db, struct pkg *p, const char *path)
			goto out;
		}
		close(from);
-
		register_backup(db, backupdir, libname);
+
		register_backup(db, p, backupdir, libname);
		close(backupdir);
		return;
	}
modified tests/frontend/backup_lib.sh
@@ -65,7 +65,7 @@ EOF
	atf_check -o ignore \
	    ls target/back/libempty.so.1
	atf_check -o inline:"/back/libempty.so.1\n" \
-
	    pkg -r ${TMPDIR}/target query "%Fp" compat-libraries
+
	    pkg -r ${TMPDIR}/target query "%Fp" test-backup-libraries
	rm foo-1.pkg
	atf_check sh ${RESOURCEDIR}/test_subr.sh new_pkg "foo" "foo" "2"
	atf_check pkg create -M foo.ucl
@@ -74,14 +74,17 @@ EOF
	    pkg -o BACKUP_LIBRARY_PATH=/back/ -o BACKUP_LIBRARIES=true \
	        -o REPOS_DIR=${TMPDIR}/reposconf -r ${TMPDIR}/target \
	        update -f
-
	version1=$(pkg -r ${TMPDIR}/target query "%v" compat-libraries)
+

+
	version1=$(pkg -r ${TMPDIR}/target query "%v" test-backup-libraries)
	atf_check -o ignore \
	    pkg -o BACKUP_LIBRARY_PATH=/back/ -o BACKUP_LIBRARIES=true \
	        -o REPOS_DIR=${TMPDIR}/reposconf -r ${TMPDIR}/target \
	        upgrade -y
-
	atf_check -o inline:"/back/libempty.so.1\n/back/libfoo.so.1\n" \
-
	    pkg -r ${TMPDIR}/target query "%Fp" compat-libraries
-
	version2=$(pkg -r ${TMPDIR}/target query "%v" compat-libraries)
+
	atf_check -o inline:"/back/libempty.so.1\n" \
+
	    pkg -r ${TMPDIR}/target query "%Fp" test-backup-libraries
+
	atf_check -o inline:"/back/libfoo.so.1\n" \
+
	    pkg -r ${TMPDIR}/target query "%Fp" foo-backup-libraries
+
	version2=$(pkg -r ${TMPDIR}/target query "%v" test-backup-libraries)
	[ ${version2} -ge ${version1} ] || \
	    atf_fail "the version hasn't been bumped ${version2} >= ${version1}"
}
@@ -160,8 +163,10 @@ EOF

	atf_check test -f ${TMPDIR}/target/back/libfoo.so.1
	atf_check test -f ${TMPDIR}/target/back/libbar.so.1
-
	atf_check -o inline:"libbar.so.1\nlibfoo.so.1\n" \
-
	    pkg -r ${TMPDIR}/target query "%b" compat-libraries
+
	atf_check -o inline:"libbar.so.1\n" \
+
	    pkg -r ${TMPDIR}/target query "%b" bar-backup-libraries
+
	atf_check -o inline:"libfoo.so.1\n" \
+
	    pkg -r ${TMPDIR}/target query "%b" foo-backup-libraries
}

# If a package foo provides libfoo.so.1 and a different package bar
@@ -236,7 +241,7 @@ EOF
	# still available via the backup libraries mechanism.
	atf_check -o ignore \
	    pkg \
-
	        -o REPOS_DIR=${TMPDIR}/reposconf -r ${TMPDIR}/target \
+
		-o REPOS_DIR=${TMPDIR}/reposconf -r ${TMPDIR}/target \
		-o BACKUP_LIBRARIES=yes \
	        upgrade -y foo bar

@@ -246,7 +251,7 @@ EOF

# A regression test for a scenario where the same shlib version is backed up
# multiple times.  This would result in a registration failure of the
-
# compat-libraries, which in turn could result in a sqlite error if this
+
# backup package, which in turn could result in a sqlite error if this
# happened during a pkg uninstall during a split upgrade.
multiple_upgrade_body()
{
@@ -382,7 +387,8 @@ EOF
	# bar-2->bar-3 upgrade.  baz-3 depends on foo-3 to try and provoke the
	# split, otherwise pkg would first upgrade baz-1->baz-3 and then there
	# would be no need to split the bar upgrade.
-
	atf_check -o ignore -e match:"compat-libraries-.* conflicts with compat-libraries-.*" \
+
	atf_check -o ignore \
+
	    -e match:"bar-backup-libraries-.* conflicts with foo-backup-libraries-.*" \
	    pkg \
	        -o REPOS_DIR=${TMPDIR}/reposconf -r ${TMPDIR}/target \
		-o BACKUP_LIBRARIES=yes \