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>
This commit is contained in:
Dan McGee 2011-07-14 15:32:03 -05:00
parent 36e48573ce
commit af357d6ab0
9 changed files with 92 additions and 9 deletions

View file

@ -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;

View file

@ -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;
if(file == NULL || backup_list == NULL) {
if(file == NULL || pkg == NULL) {
return NULL;
}
/* 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;
if(strcmp(file, backup->name) == 0) {

View file

@ -24,7 +24,7 @@
#include "alpm.h"
int _alpm_split_backup(const char *string, alpm_backup_t **backup);
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);
void _alpm_backup_free(alpm_backup_t *backup);
alpm_backup_t *_alpm_backup_dup(const alpm_backup_t *backup);

View file

@ -549,6 +549,22 @@ alpm_list_t *_alpm_db_find_fileconflicts(alpm_handle_t *handle,
free(rpath);
}
/* is the file unowned and in the backup list of the new package? */
if(!resolved_conflict && _alpm_needbackup(filestr, p1)) {
alpm_list_t *local_pkgs = _alpm_db_get_pkgcache(handle->db_local);
int found = 0;
for(k = local_pkgs; k && !found; k = k->next) {
if(_alpm_filelist_contains(alpm_pkg_get_files(k->data), filestr)) {
found = 1;
}
}
if(!found) {
_alpm_log(handle, ALPM_LOG_DEBUG,
"file was unowned but in new backup list: %s\n", path);
resolved_conflict = 1;
}
}
if(!resolved_conflict) {
conflicts = add_fileconflict(handle, conflicts,
ALPM_FILECONFLICT_FILESYSTEM, path, p1->name, NULL);

View file

@ -255,7 +255,7 @@ static void unlink_file(alpm_handle_t *handle, alpm_pkg_t *info,
}
} else {
/* if the file needs backup and has been modified, back it up to .pacsave */
alpm_backup_t *backup = _alpm_needbackup(fileobj->name, alpm_pkg_get_backup(info));
alpm_backup_t *backup = _alpm_needbackup(fileobj->name, info);
if(backup) {
if(nosave) {
_alpm_log(handle, ALPM_LOG_DEBUG, "transaction is set to NOSAVE, not backing up '%s'\n", file);

View file

@ -1,4 +1,4 @@
self.description = "FS#8156"
self.description = "FS#8156- conflict between directory and incoming symlink"
p1 = pmpkg("pkg1")
p1.files = ["test/",

View file

@ -0,0 +1,22 @@
self.description = "Upgrade a package, with a file entering the pkg in 'backup' (changed)"
self.filesystem = ["etc/dummy.conf"]
lp = pmpkg("dummy")
lp.files = ["usr/bin/dummy"]
self.addpkg2db("local", lp)
p = pmpkg("dummy", "1.0-2")
p.files = ["usr/bin/dummy",
"etc/dummy.conf*"]
p.backup = ["etc/dummy.conf"]
self.addpkg(p)
self.args = "-U %s" % p.filename()
self.addrule("PACMAN_RETCODE=0")
self.addrule("PKG_VERSION=dummy|1.0-2")
self.addrule("FILE_PACNEW=etc/dummy.conf")
self.addrule("!FILE_PACSAVE=etc/dummy.conf")
self.addrule("!FILE_PACORIG=etc/dummy.conf")
self.addrule("FILE_EXIST=etc/dummy.conf")

View file

@ -0,0 +1,22 @@
self.description = "Upgrade a package, with a file entering the pkg in 'backup' (unchanged)"
self.filesystem = ["etc/dummy.conf"]
lp = pmpkg("dummy")
lp.files = ["usr/bin/dummy"]
self.addpkg2db("local", lp)
p = pmpkg("dummy", "1.0-2")
p.files = ["usr/bin/dummy",
"etc/dummy.conf"]
p.backup = ["etc/dummy.conf"]
self.addpkg(p)
self.args = "-U %s" % p.filename()
self.addrule("PACMAN_RETCODE=0")
self.addrule("PKG_VERSION=dummy|1.0-2")
self.addrule("!FILE_PACNEW=etc/dummy.conf")
self.addrule("!FILE_PACSAVE=etc/dummy.conf")
self.addrule("!FILE_PACORIG=etc/dummy.conf")
self.addrule("FILE_EXIST=etc/dummy.conf")

View file

@ -0,0 +1,24 @@
self.description = "Upgrade a package, with an owned file entering the pkg in 'backup'"
lp = pmpkg("dummy")
lp.files = ["usr/bin/dummy"]
self.addpkg2db("local", lp)
lp2 = pmpkg("dummy2")
lp2.files = ["etc/dummy.conf"]
self.addpkg2db("local", lp2)
p = pmpkg("dummy", "1.0-2")
p.files = ["usr/bin/dummy",
"etc/dummy.conf*"]
p.backup = ["etc/dummy.conf"]
self.addpkg(p)
self.args = "-U %s" % p.filename()
self.addrule("PACMAN_RETCODE=1")
self.addrule("PKG_VERSION=dummy|1.0-1")
self.addrule("!FILE_PACNEW=etc/dummy.conf")
self.addrule("!FILE_PACSAVE=etc/dummy.conf")
self.addrule("!FILE_PACORIG=etc/dummy.conf")
self.addrule("FILE_EXIST=etc/dummy.conf")