1
0
mirror of https://github.com/moparisthebest/pacman synced 2024-12-22 15:58:50 -05:00

Do not create .pacsave with -R, if the file is unchanged

This fixes FS#15546

Also fix the interface of unlink_file which was really stupid..
(alpm_list_t used with only one element)

Signed-off-by: Xavier Chantry <shiningxc@gmail.com>
Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
Xavier Chantry 2009-07-19 19:49:59 +02:00 committed by Dan McGee
parent 45f90de0eb
commit 5d15bb68f7
2 changed files with 27 additions and 24 deletions

View File

@ -228,25 +228,18 @@ static int can_remove_file(pmtrans_t *trans, const char *path)
/* Helper function for iterating through a package's file and deleting them
* Used by _alpm_remove_commit. */
static void unlink_file(pmpkg_t *info, alpm_list_t *lp, pmtrans_t *trans)
static void unlink_file(pmpkg_t *info, char *filename, pmtrans_t *trans)
{
struct stat buf;
int needbackup = 0;
char file[PATH_MAX+1];
ALPM_LOG_FUNC;
char *hash = _alpm_needbackup(lp->data, alpm_pkg_get_backup(info));
if(hash) {
needbackup = 1;
FREE(hash);
}
snprintf(file, PATH_MAX, "%s%s", handle->root, (char *)lp->data);
snprintf(file, PATH_MAX, "%s%s", handle->root, filename);
if(trans->type == PM_TRANS_TYPE_REMOVEUPGRADE) {
/* check noupgrade */
if(alpm_list_find_str(handle->noupgrade, lp->data)) {
if(alpm_list_find_str(handle->noupgrade, filename)) {
_alpm_log(PM_LOG_DEBUG, "Skipping removal of '%s' due to NoUpgrade\n",
file);
return;
@ -277,24 +270,34 @@ static void unlink_file(pmpkg_t *info, alpm_list_t *lp, pmtrans_t *trans)
_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->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);
alpm_logaction("warning: %s saved as %s\n", file, newpath);
return;
} else {
}
/* if the file needs backup and has been modified, back it up to .pacsave */
char *pkghash = _alpm_needbackup(filename, alpm_pkg_get_backup(info));
if(pkghash) {
if(trans->flags & PM_TRANS_FLAG_NOSAVE) {
_alpm_log(PM_LOG_DEBUG, "transaction is set to NOSAVE, not backing up '%s'\n", file);
} else {
char *filehash = alpm_compute_md5sum(file);
int cmp = strcmp(filehash,pkghash);
FREE(filehash);
FREE(pkghash);
if(cmp != 0) {
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);
alpm_logaction("warning: %s saved as %s\n", file, newpath);
return;
}
}
}
_alpm_log(PM_LOG_DEBUG, "unlinking %s\n", file);
if(unlink(file) == -1) {
_alpm_log(PM_LOG_ERROR, _("cannot remove file '%s': %s\n"),
(char *)lp->data, strerror(errno));
filename, strerror(errno));
}
}
}
@ -359,7 +362,7 @@ int _alpm_remove_commit(pmtrans_t *trans, pmdb_t *db)
/* iterate through the list backwards, unlinking files */
newfiles = alpm_list_reverse(files);
for(lp = newfiles; lp; lp = alpm_list_next(lp)) {
unlink_file(info, lp, trans);
unlink_file(info, lp->data, trans);
/* update progress bar after each file */
percent = (double)position / (double)filenum;

View File

@ -1,4 +1,4 @@
self.description = "Remove a package with a file marked for backup"
self.description = "Remove a package with an unchanged file marked for backup"
p1 = pmpkg("dummy")
p1.files = ["etc/dummy.conf"]
@ -10,4 +10,4 @@ self.args = "-R %s" % p1.name
self.addrule("PACMAN_RETCODE=0")
self.addrule("!PKG_EXIST=dummy")
self.addrule("!FILE_EXIST=etc/dummy.conf")
self.addrule("FILE_PACSAVE=etc/dummy.conf")
self.addrule("!FILE_PACSAVE=etc/dummy.conf")