1
0
mirror of https://github.com/moparisthebest/pacman synced 2024-11-15 13:55:09 -05:00

extract_single_file: consolidate needbackup checks

We need to know if a file needs to be backed up for all extracted files.

Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com>
This commit is contained in:
Andrew Gregory 2014-10-01 01:14:57 -04:00 committed by Allan McRae
parent 3b20561748
commit 63660afbc7

View File

@ -147,16 +147,15 @@ static int try_rename(alpm_handle_t *handle, const char *src, const char *dest)
static int extract_single_file(alpm_handle_t *handle, struct archive *archive, static int extract_single_file(alpm_handle_t *handle, struct archive *archive,
struct archive_entry *entry, alpm_pkg_t *newpkg, alpm_pkg_t *oldpkg) struct archive_entry *entry, alpm_pkg_t *newpkg, alpm_pkg_t *oldpkg)
{ {
const char *entryname; const char *entryname = archive_entry_pathname(entry);
mode_t entrymode; mode_t entrymode = archive_entry_mode(entry);
alpm_backup_t *backup = _alpm_needbackup(entryname, newpkg);
char filename[PATH_MAX]; /* the actual file we're extracting */ char filename[PATH_MAX]; /* the actual file we're extracting */
int needbackup = 0, notouch = 0; int needbackup = 0, notouch = 0;
const char *hash_orig = NULL; const char *hash_orig = NULL;
char *entryname_orig = NULL; char *entryname_orig = NULL;
int errors = 0; int errors = 0;
struct stat lsbuf;
entryname = archive_entry_pathname(entry);
entrymode = archive_entry_mode(entry);
if(strcmp(entryname, ".INSTALL") == 0) { if(strcmp(entryname, ".INSTALL") == 0) {
/* the install script goes inside the db */ /* the install script goes inside the db */
@ -214,7 +213,6 @@ static int extract_single_file(alpm_handle_t *handle, struct archive *archive,
* 6- skip extraction, dir already exists. * 6- skip extraction, dir already exists.
*/ */
struct stat lsbuf;
if(llstat(filename, &lsbuf) != 0) { if(llstat(filename, &lsbuf) != 0) {
/* cases 1,2: file doesn't exist, skip all backup checks */ /* cases 1,2: file doesn't exist, skip all backup checks */
} else { } else {
@ -267,25 +265,17 @@ static int extract_single_file(alpm_handle_t *handle, struct archive *archive,
if(_alpm_fnmatch_patterns(handle->noupgrade, entryname) == 0) { if(_alpm_fnmatch_patterns(handle->noupgrade, entryname) == 0) {
notouch = 1; notouch = 1;
} else { } else {
alpm_backup_t *backup; alpm_backup_t *oldbackup;
/* go to the backup array and see if our conflict is there */ if(oldpkg && (oldbackup = _alpm_needbackup(entryname, oldpkg))) {
/* check newpkg first, so that adding backup files is retroactive */ hash_orig = oldbackup->hash;
backup = _alpm_needbackup(entryname, newpkg);
if(backup) {
needbackup = 1; needbackup = 1;
} } else if(backup) {
/* allow adding backup files retroactively */
/* check oldpkg for a backup entry, store the hash if available */
if(oldpkg) {
backup = _alpm_needbackup(entryname, oldpkg);
if(backup) {
hash_orig = backup->hash;
needbackup = 1; needbackup = 1;
} }
} }
} }
} }
}
/* we need access to the original entryname later after calls to /* we need access to the original entryname later after calls to
* archive_entry_set_pathname(), so we need to dupe it and free() later */ * archive_entry_set_pathname(), so we need to dupe it and free() later */
@ -310,16 +300,10 @@ static int extract_single_file(alpm_handle_t *handle, struct archive *archive,
hash_pkg = alpm_compute_md5sum(checkfile); hash_pkg = alpm_compute_md5sum(checkfile);
/* update the md5 hash in newpkg's backup (it will be the new original) */ /* update the md5 hash in newpkg's backup (it will be the new original) */
alpm_list_t *i; if(backup) {
for(i = alpm_pkg_get_backup(newpkg); i; i = i->next) {
alpm_backup_t *backup = i->data;
char *newhash;
if(!backup->name || strcmp(backup->name, entryname_orig) != 0) {
continue;
}
STRDUP(newhash, hash_pkg, errors++; handle->pm_errno = ALPM_ERR_MEMORY; goto needbackup_cleanup);
FREE(backup->hash); FREE(backup->hash);
backup->hash = newhash; STRDUP(backup->hash, hash_pkg,
errors++; handle->pm_errno = ALPM_ERR_MEMORY; goto needbackup_cleanup);
} }
_alpm_log(handle, ALPM_LOG_DEBUG, "checking hashes for %s\n", entryname_orig); _alpm_log(handle, ALPM_LOG_DEBUG, "checking hashes for %s\n", entryname_orig);
@ -466,17 +450,9 @@ needbackup_cleanup:
} }
/* calculate an hash if this is in newpkg's backup */ /* calculate an hash if this is in newpkg's backup */
alpm_list_t *i; if(backup) {
for(i = alpm_pkg_get_backup(newpkg); i; i = i->next) {
alpm_backup_t *backup = i->data;
char *newhash;
if(!backup->name || strcmp(backup->name, entryname_orig) != 0) {
continue;
}
_alpm_log(handle, ALPM_LOG_DEBUG, "appending backup entry for %s\n", entryname_orig);
newhash = alpm_compute_md5sum(filename);
FREE(backup->hash); FREE(backup->hash);
backup->hash = newhash; backup->hash = alpm_compute_md5sum(filename);
} }
} }
free(entryname_orig); free(entryname_orig);