Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2007-09-23 14:43:03 -0500
committerDan McGee <dan@archlinux.org>2007-09-23 20:48:04 -0500
commit843d368ef60a74719dfc74a27de3fe3ef441951f (patch)
treee33e186ecf4ee8e86f31bea9f9aa028b0a362810
parent105fd40a4a9b221df0186e7500fe491b3b96d823 (diff)
libalpm/add.c: fix backup array issue
As seen with the recent upgrade of pacman and the removal of the pacman.d/current mirrorlist, files that were formerly in the backup array get deleted upon their removal, which could be dangerous. Instead, we should use the combined backup array of the old and new package. This fix should address this issue in a relatively straightforward way. In addition, old files should be moved to pacsave locations as expected. Signed-off-by: Dan McGee <dan@archlinux.org>
-rw-r--r--lib/libalpm/add.c18
-rw-r--r--lib/libalpm/remove.c28
-rw-r--r--pactest/tests/upgrade010.py1
-rw-r--r--pactest/tests/upgrade020.py1
-rw-r--r--pactest/tests/upgrade021.py1
-rw-r--r--pactest/tests/upgrade022.py1
-rw-r--r--pactest/tests/upgrade023.py1
-rw-r--r--pactest/tests/upgrade025.py1
8 files changed, 32 insertions, 20 deletions
diff --git a/lib/libalpm/add.c b/lib/libalpm/add.c
index e9225da1..86e80778 100644
--- a/lib/libalpm/add.c
+++ b/lib/libalpm/add.c
@@ -295,18 +295,26 @@ static int upgrade_remove(pmpkg_t *oldpkg, pmpkg_t *newpkg, pmtrans_t *trans, pm
tr->skip_remove = alpm_list_strdup(trans->skip_remove);
const alpm_list_t *b;
- /* Add files in the NEW package's backup array to the noupgrade array
+ /* Add files in the OLD and NEW backup array to the NoUpgrade array
* so this removal operation doesn't kill them */
- /* TODO if we add here, all backup=() entries for all targets, new and
- * old, we cover all bases, including backup=() locations changing hands.
- * But is this viable? */
alpm_list_t *old_noupgrade = alpm_list_strdup(handle->noupgrade);
- for(b = alpm_pkg_get_backup(newpkg); b; b = b->next) {
+ /* old package backup list */
+ for(b = alpm_pkg_get_backup(oldpkg); b; b = b->next) {
const char *backup = b->data;
_alpm_log(PM_LOG_DEBUG, "adding %s to the NoUpgrade array temporarily\n",
backup);
handle->noupgrade = alpm_list_add(handle->noupgrade, strdup(backup));
}
+ /* new package backup list */
+ for(b = alpm_pkg_get_backup(newpkg); b; b = b->next) {
+ const char *backup = b->data;
+ /* make sure we don't add duplicate entries */
+ if(!alpm_list_find(handle->noupgrade, backup)) {
+ _alpm_log(PM_LOG_DEBUG, "adding %s to the NoUpgrade array temporarily\n",
+ backup);
+ handle->noupgrade = alpm_list_add(handle->noupgrade, strdup(backup));
+ }
+ }
int ret = _alpm_remove_commit(tr, db);
diff --git a/lib/libalpm/remove.c b/lib/libalpm/remove.c
index 6f119ba1..7fbf675a 100644
--- a/lib/libalpm/remove.c
+++ b/lib/libalpm/remove.c
@@ -200,7 +200,8 @@ static void unlink_file(pmpkg_t *info, alpm_list_t *lp, pmtrans_t *trans)
if(trans->type == PM_TRANS_TYPE_REMOVEUPGRADE) {
/* check noupgrade */
if(alpm_list_find_str(handle->noupgrade, lp->data)) {
- _alpm_log(PM_LOG_DEBUG, "Skipping removal of '%s' due to NoUpgrade\n", file);
+ _alpm_log(PM_LOG_DEBUG, "Skipping removal of '%s' due to NoUpgrade\n",
+ file);
return;
}
}
@@ -212,7 +213,7 @@ static void unlink_file(pmpkg_t *info, alpm_list_t *lp, pmtrans_t *trans)
if(S_ISDIR(buf.st_mode)) {
if(rmdir(file)) {
- /* this is okay, other pakcages are probably using it (like /usr) */
+ /* this is okay, other packages are probably using it (like /usr) */
_alpm_log(PM_LOG_DEBUG, "keeping directory %s\n", file);
} else {
_alpm_log(PM_LOG_DEBUG, "removing directory %s\n", file);
@@ -222,22 +223,19 @@ static void unlink_file(pmpkg_t *info, alpm_list_t *lp, pmtrans_t *trans)
* see the big comment block in db_find_conflicts() for an
* explanation. */
if(alpm_list_find_str(trans->skip_remove, file)) {
- _alpm_log(PM_LOG_DEBUG, "%s is in trans->skip_remove, skipping removal\n", file);
+ _alpm_log(PM_LOG_DEBUG, "%s is in trans->skip_remove, skipping removal\n",
+ file);
return;
} else if(needbackup) {
/* if the file is flagged, back it up to .pacsave */
- if(!(trans->type == PM_TRANS_TYPE_REMOVEUPGRADE)) {
- /* if it was an upgrade, the file would be left alone because
- * pacman_add() would handle it */
- if(!(trans->flags & PM_TRANS_FLAG_NOSAVE)) {
- char newpath[PATH_MAX];
- snprintf(newpath, PATH_MAX, "%s.pacsave", file);
- rename(file, newpath);
- _alpm_log(PM_LOG_WARNING, _("%s saved as %s\n"), file, newpath);
- return;
- } else {
- _alpm_log(PM_LOG_DEBUG, "transaction is set to NOSAVE, not backing up '%s'\n", file);
- }
+ if(!(trans->flags & PM_TRANS_FLAG_NOSAVE)) {
+ char newpath[PATH_MAX];
+ snprintf(newpath, PATH_MAX, "%s.pacsave", file);
+ rename(file, newpath);
+ _alpm_log(PM_LOG_WARNING, _("%s saved as %s\n"), file, newpath);
+ return;
+ } else {
+ _alpm_log(PM_LOG_DEBUG, "transaction is set to NOSAVE, not backing up '%s'\n", file);
}
}
_alpm_log(PM_LOG_DEBUG, "unlinking %s\n", file);
diff --git a/pactest/tests/upgrade010.py b/pactest/tests/upgrade010.py
index 04f3d816..633ef7e4 100644
--- a/pactest/tests/upgrade010.py
+++ b/pactest/tests/upgrade010.py
@@ -15,3 +15,4 @@ self.args = "-U %s" % p.filename()
self.addrule("PKG_VERSION=dummy|1.0-2")
self.addrule("!FILE_MODIFIED=etc/dummy.conf")
self.addrule("FILE_PACNEW=etc/dummy.conf")
+self.addrule("!FILE_PACSAVE=etc/dummy.conf")
diff --git a/pactest/tests/upgrade020.py b/pactest/tests/upgrade020.py
index ab5fe225..6a7994bb 100644
--- a/pactest/tests/upgrade020.py
+++ b/pactest/tests/upgrade020.py
@@ -15,3 +15,4 @@ self.args = "-U %s" % p.filename()
self.addrule("PKG_VERSION=dummy|1.0-2")
self.addrule("FILE_MODIFIED=etc/dummy.conf")
self.addrule("!FILE_PACNEW=etc/dummy.conf")
+self.addrule("!FILE_PACSAVE=etc/dummy.conf")
diff --git a/pactest/tests/upgrade021.py b/pactest/tests/upgrade021.py
index 1ac0ceb5..b45ea18a 100644
--- a/pactest/tests/upgrade021.py
+++ b/pactest/tests/upgrade021.py
@@ -15,3 +15,4 @@ self.args = "-U %s" % p.filename()
self.addrule("PKG_VERSION=dummy|1.0-2")
self.addrule("!FILE_MODIFIED=etc/dummy.conf")
self.addrule("!FILE_PACNEW=etc/dummy.conf")
+self.addrule("!FILE_PACSAVE=etc/dummy.conf")
diff --git a/pactest/tests/upgrade022.py b/pactest/tests/upgrade022.py
index 6bf12c15..dcf7ae01 100644
--- a/pactest/tests/upgrade022.py
+++ b/pactest/tests/upgrade022.py
@@ -15,3 +15,4 @@ self.args = "-U %s" % p.filename()
self.addrule("PKG_VERSION=dummy|1.0-2")
self.addrule("!FILE_MODIFIED=etc/dummy.conf")
self.addrule("FILE_PACNEW=etc/dummy.conf")
+self.addrule("!FILE_PACSAVE=etc/dummy.conf")
diff --git a/pactest/tests/upgrade023.py b/pactest/tests/upgrade023.py
index 68a29df2..d1d2e314 100644
--- a/pactest/tests/upgrade023.py
+++ b/pactest/tests/upgrade023.py
@@ -15,3 +15,4 @@ self.addrule("PKG_VERSION=dummy|1.1-1")
self.addrule("!FILE_MODIFIED=etc/dummy.conf")
# Do we want this pacnew or not?
self.addrule("FILE_PACNEW=etc/dummy.conf")
+self.addrule("!FILE_PACSAVE=etc/dummy.conf")
diff --git a/pactest/tests/upgrade025.py b/pactest/tests/upgrade025.py
index b78a2dd1..2c9c06f3 100644
--- a/pactest/tests/upgrade025.py
+++ b/pactest/tests/upgrade025.py
@@ -13,4 +13,5 @@ self.args = "-U %s" % p.filename()
self.addrule("PKG_VERSION=dummy|1.0-2")
self.addrule("FILE_PACSAVE=etc/dummy.conf")
+self.addrule("!FILE_PACNEW=etc/dummy.conf")
self.addrule("FILE_EXIST=etc/dummy.conf")