From 57407ed4e9db4b8cd14bcf44958a040d981d3021 Mon Sep 17 00:00:00 2001 From: Natanael Copa Date: Sun, 18 Jan 2009 14:49:18 +0100 Subject: 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. --- src/database.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'src/database.c') 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); -- cgit v1.2.3-70-g09d2