Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
libpkg: Implement backup_libraries for split upgrades
Mark Johnston committed 8 months ago
commit 433a0790023641526b5946274d351aa4d104a1d5
parent 32164fc
4 files changed +31 -19
modified libpkg/backup_lib.c
@@ -90,7 +90,7 @@ register_backup(struct pkgdb *db, int fd, const char *path)
	return (retcode);
}

-
void
+
static void
backup_library(struct pkgdb *db, struct pkg *p, const char *path)
{
	const char *libname;
@@ -101,13 +101,12 @@ backup_library(struct pkgdb *db, struct pkg *p, const char *path)

	if ((libname = strrchr(path, '/')) == NULL)
		return;
+
	/* skip the initial / */
+
	libname++;

	pkg_open_root_fd(p);
	to = -1;

-
	/* skip the initial / */
-
	libname++;
-

	from = openat(p->rootfd, RELATIVE_PATH(path), O_RDONLY);
	if (from == -1) {
		pkg_debug(2, "unable to backup %s:%s", path, strerror(errno));
@@ -177,3 +176,22 @@ out:
	if (to >= 0)
		close(to);
}
+

+
/*
+
 * We're about to remove an installed file as part of an upgrade.  See if it's a
+
 * library and whether the user asked us to back up libraries, and if so, back
+
 * it up.
+
 */
+
void
+
pkg_maybe_backup_library(struct pkgdb *db, struct pkg *pkg, const char *path)
+
{
+
	const char *libname;
+

+
	if (!ctx.backup_libraries)
+
		return;
+

+
	libname = strrchr(path, '/');
+
	if (libname != NULL &&
+
	    charv_search(&pkg->shlibs_provided, libname + 1) != NULL)
+
		backup_library(db, pkg, path);
+
}
modified libpkg/pkg_add.c
@@ -1459,15 +1459,7 @@ pkg_add_cleanup_old(struct pkgdb *db, struct pkg *old, struct pkg *new, struct t
			    pkg_config_get("FILES_IGNORE_GLOB"),
			    pkg_config_get("FILES_IGNORE_REGEX"))) {
				pkg_debug(2, "File %s is not in the new package", f->path);
-
				if (ctx.backup_libraries) {
-
					const char *libname;
-
					libname = strrchr(f->path, '/');
-
					if (libname != NULL &&
-
					    charv_search(&old->shlibs_provided, libname+1) != NULL) {
-
						backup_library(db, old, f->path);
-
					}
-
				}
-

+
				pkg_maybe_backup_library(db, old, f->path);
				trigger_is_it_a_cleanup(t, f->path);
				pkg_delete_file(old, f);
			}
modified libpkg/pkg_delete.c
@@ -100,7 +100,7 @@ pkg_delete(struct pkg *pkg, struct pkg *rpkg, struct pkgdb *db, int flags,
			return (ret);
	}

-
	ret = pkg_delete_files(pkg, rpkg, flags, t);
+
	ret = pkg_delete_files(db, pkg, rpkg, flags, t);
	if (ret == EPKG_CANCEL)
		cancel = 1;
	else if (ret != EPKG_OK)
@@ -353,11 +353,10 @@ pkg_delete_skip_config(struct pkg *pkg, struct pkg *rpkg, struct pkg_file *file,
}

int
-
pkg_delete_files(struct pkg *pkg, struct pkg *rpkg, int flags,
+
pkg_delete_files(struct pkgdb *db, struct pkg *pkg, struct pkg *rpkg, int flags,
    struct triggers *t)
{
	struct pkg_file	*file = NULL;
-

	int		nfiles, cur_file = 0;
	int		retcode = EPKG_OK;

@@ -371,6 +370,8 @@ pkg_delete_files(struct pkg *pkg, struct pkg *rpkg, int flags,
	while (pkg_files(pkg, &file) == EPKG_OK) {
		if (pkg_delete_skip_config(pkg, rpkg, file, flags))
			continue;
+
		if ((flags & PKG_DELETE_UPGRADE) != 0)
+
			pkg_maybe_backup_library(db, pkg, file->path);
		append_touched_file(file->path);
		if (pkg_emit_progress_tick(cur_file++, nfiles))
			retcode = EPKG_CANCEL;
modified libpkg/private/pkg.h
@@ -707,8 +707,8 @@ pkg_formats packing_format_from_string(const char *str);
const char* packing_format_to_string(pkg_formats format);
bool packing_is_valid_format(const char *str);

-
int pkg_delete_files(struct pkg *pkg, struct pkg *rpkg, int flags,
-
    struct triggers *t);
+
int pkg_delete_files(struct pkgdb *db, struct pkg *pkg, struct pkg *rpkg,
+
    int flags, struct triggers *t);
int pkg_delete_dirs(struct pkgdb *db, struct pkg *pkg, struct pkg *p);

/* pkgdb commands */
@@ -855,7 +855,8 @@ int pkg_add_fromdir(struct pkg *, const char *, struct pkgdb *db);
struct pkg_dep* pkg_adddep_chain(struct pkg_dep *chain,
		struct pkg *pkg, const char *name, const char *origin, const
		char *version, bool locked);
-
void backup_library(struct pkgdb *, struct pkg *, const char *);
+
void pkg_maybe_backup_library(struct pkgdb *db, struct pkg *pkg,
+
    const char *path);
int suggest_arch(struct pkg *, bool);
int set_attrsat(int fd, const char *path, mode_t perm, uid_t uid, gid_t gid, const struct timespec *ats, const struct timespec *mts);