db: create .apk-new even if file not in db

Protect files in protected dirs even if the file is not previously
registered in the database. We do so by always extracting to a
.apk-new file name, compare the checksums afterwards and rename if
file was identical.
cute-signatures
Natanael Copa 2009-01-18 14:49:18 +01:00
parent 4d5efe6a05
commit 57407ed4e9
1 changed files with 8 additions and 5 deletions

View File

@ -1049,16 +1049,19 @@ static int apk_db_install_archive_entry(void *_ctx,
}
if ((diri->dir->flags & APK_DBDIRF_PROTECTED) &&
csum_valid(file->csum) &&
apk_file_get_info(ae->name, &fi) == 0 &&
memcmp(file->csum, fi.csum, sizeof(csum_t)) != 0) {
/* Protected file, which is modified locally.
* Extract to separate place */
apk_file_get_info(ae->name, &fi) == 0) {
/* Protected file. Extract to separate place */
snprintf(alt_name, sizeof(alt_name),
"%s/%s.apk-new",
diri->dir->dirname, file->filename);
r = apk_archive_entry_extract(ae, is, alt_name,
extract_cb, ctx);
if (memcmp(ae->csum, fi.csum, sizeof(csum_t)) == 0) {
/* not modified locally. rename to original */
if (rename(alt_name, ae->name) < 0)
apk_warning("%s: %s", ae->name,
strerror(errno));
}
} else {
r = apk_archive_entry_extract(ae, is, NULL,
extract_cb, ctx);