Commit 57407ed4 authored by Natanael Copa's avatar Natanael Copa

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.
parent 4d5efe6a
......@@ -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);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment