Allow fileconflict if unowned file moving into backup array
The bulk of this commit is adding new tests to ensure the new behavior
works without disrupting old behavior. This is a relatively sane maneuver
when a package adds a conf file (e.g. '/etc/mercurial/hgrc') that was
not previously in the package, but it is placed in the backup array. In
essence, we can treat the existing file as having always been a part of
the package and do our normal compare/install as pacnew logic checks.
Signed-off-by: Dan McGee <dan@archlinux.org>
---
Focus mainly on the one new check block in conflict.c - the rest is a bit of
simplification to the alpm_needbackup() call since we always fetch the package
backup list from a package anyway, as well as adding 3 tests.
diff --git a/lib/libalpm/add.c b/lib/libalpm/add.c
index e182746..5e1bb8d 100644
--- a/lib/libalpm/add.c
+++ b/lib/libalpm/add.c
@@ -255,7 +255,7 @@ static int extract_single_file(alpm_handle_t *handle, struct archive *archive,
alpm_backup_t *backup;
/* go to the backup array and see if our conflict is there */
/* check newpkg first, so that adding backup files is retroactive */
- backup = _alpm_needbackup(entryname, alpm_pkg_get_backup(newpkg));
+ backup = _alpm_needbackup(entryname, newpkg);
if(backup) {
/* if we force hash_orig to be non-NULL retroactive backup works */
hash_orig = "";
@@ -264,7 +264,7 @@ static int extract_single_file(alpm_handle_t *handle, struct archive *archive,
/* check oldpkg for a backup entry, store the hash if available */
if(oldpkg) {
- backup = _alpm_needbackup(entryname, alpm_pkg_get_backup(oldpkg));
+ backup = _alpm_needbackup(entryname, oldpkg);
if(backup) {
hash_orig = backup->hash;
needbackup = 1;
diff --git a/lib/libalpm/backup.c b/lib/libalpm/backup.c
index becc7be..728c1d0 100644
--- a/lib/libalpm/backup.c
+++ b/lib/libalpm/backup.c
@@ -58,16 +58,15 @@ int _alpm_split_backup(const char *string, alpm_backup_t **backup)
/* Look for a filename in a alpm_pkg_t.backup list. If we find it,
* then we return the full backup entry.
*/
-alpm_backup_t *_alpm_needbackup(const char *file, const alpm_list_t *backup_list)
+alpm_backup_t *_alpm_needbackup(const char *file, alpm_pkg_t *pkg)
{
const alpm_list_t *lp;
- /* run through the backup list and parse out the hash for our file */
- for(lp = backup_list; lp; lp = lp->next) {
+ for(lp = alpm_pkg_get_backup(pkg); lp; lp = lp->next) {
alpm_backup_t *backup = lp->data;