[pacman-dev] [PATCH 1/3] alpm: add ALPM_TRANS_FLAG_NOKEEP

morganamilo morganamilo at archlinux.org
Mon Sep 20 19:35:16 UTC 2021


this flag prevents backup files from being kept on package installation.
This is useful for resetting a package's config files back to their
original state.

Implements FS#59908 although with it's own flag name instead of reusing
nosave. This allows nokeep to optionally create a pacnew that you can
then choose to disable by also setting nosave.

---

I actually very dislike NOKEEP but it was the best I could come up with

I would have prefered overwrite or nosave but they are taken. Better
names are welcome.
---
 lib/libalpm/alpm.h   | 3 ++-
 lib/libalpm/remove.c | 4 +++-
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h
index 8d8fe243..c6048b63 100644
--- a/lib/libalpm/alpm.h
+++ b/lib/libalpm/alpm.h
@@ -2704,7 +2704,8 @@ int alpm_pkg_mtree_close(const alpm_pkg_t *pkg, struct archive *archive);
 typedef enum _alpm_transflag_t {
 	/** Ignore dependency checks. */
 	ALPM_TRANS_FLAG_NODEPS = 1,
-	/* (1 << 1) flag can go here */
+	/** Don't keep backup files when installing packages. */
+	ALPM_TRANS_FLAG_NOKEEP = (1 << 1),
 	/** Delete files even if they are tagged as backup. */
 	ALPM_TRANS_FLAG_NOSAVE = (1 << 2),
 	/** Ignore version numbers when checking dependencies. */
diff --git a/lib/libalpm/remove.c b/lib/libalpm/remove.c
index de39724a..233fff0c 100644
--- a/lib/libalpm/remove.c
+++ b/lib/libalpm/remove.c
@@ -575,7 +575,9 @@ static int should_skip_file(alpm_handle_t *handle,
 {
 	return _alpm_fnmatch_patterns(handle->noupgrade, path) == 0
 		|| alpm_list_find_str(handle->trans->skip_remove, path)
-		|| (newpkg && _alpm_needbackup(path, newpkg)
+		|| (!(handle->trans->flags & ALPM_TRANS_FLAG_NOKEEP)
+				&& newpkg
+				&& _alpm_needbackup(path, newpkg)
 				&& alpm_filelist_contains(alpm_pkg_get_files(newpkg), path));
 }
 
-- 
2.33.0



More information about the pacman-dev mailing list