summaryrefslogtreecommitdiff
path: root/src/database.c
diff options
context:
space:
mode:
authorNatanael Copa <natanael.copa@gmail.com>2009-01-18 14:49:18 +0100
committerNatanael Copa <natanael.copa@gmail.com>2009-01-18 14:49:18 +0100
commit57407ed4e9db4b8cd14bcf44958a040d981d3021 (patch)
treef56ad21c96c3a9e73b4fc1a3f7dbdb28fb7b3ea3 /src/database.c
parent4d5efe6a05d6f4f4db9901347cf5f7cb9002bed9 (diff)
downloadapk-tools-57407ed4e9db4b8cd14bcf44958a040d981d3021.tar.gz
apk-tools-57407ed4e9db4b8cd14bcf44958a040d981d3021.tar.bz2
apk-tools-57407ed4e9db4b8cd14bcf44958a040d981d3021.tar.xz
apk-tools-57407ed4e9db4b8cd14bcf44958a040d981d3021.zip
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.
Diffstat (limited to 'src/database.c')
-rw-r--r--src/database.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/src/database.c b/src/database.c
index 5f3de74..118870d 100644
--- a/src/database.c
+++ b/src/database.c
@@ -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);