diff options
author | Timo Teras <timo.teras@iki.fi> | 2009-07-22 12:00:56 +0300 |
---|---|---|
committer | Timo Teras <timo.teras@iki.fi> | 2009-07-22 12:00:56 +0300 |
commit | 0dadc27ce1cfe84585a747d57e7d3bcafc1069eb (patch) | |
tree | 43f72c2856628d625644d21f3c8e89a0370a6664 | |
parent | 680a3015114ce0375604a389139831f242769f60 (diff) | |
download | apk-tools-0dadc27ce1cfe84585a747d57e7d3bcafc1069eb.tar.gz apk-tools-0dadc27ce1cfe84585a747d57e7d3bcafc1069eb.tar.bz2 apk-tools-0dadc27ce1cfe84585a747d57e7d3bcafc1069eb.tar.xz apk-tools-0dadc27ce1cfe84585a747d57e7d3bcafc1069eb.zip |
db: fix protected directory handling
do not overwrite untracked files.
-rw-r--r-- | src/database.c | 45 |
1 files changed, 13 insertions, 32 deletions
diff --git a/src/database.c b/src/database.c index db0a4eb..2cad438 100644 --- a/src/database.c +++ b/src/database.c @@ -1475,13 +1475,20 @@ static void apk_db_migrate_files(struct apk_database *db, ofile = (struct apk_db_file *) apk_hash_get_hashed( &db->installed.files, APK_BLOB_BUF(&key), hash); + r = apk_file_get_info(name, + ofile ? ofile->csum.type : APK_CHECKSUM_NONE, + &fi); if ((diri->dir->flags & APK_DBDIRF_PROTECTED) && - ofile != NULL && - apk_file_get_info(name, ofile->csum.type, &fi) == 0 && - apk_checksum_compare(&ofile->csum, &fi.csum) != 0) { - /* Protected dir and existing file has been - * changed */ - if (ofile->csum.type != file->csum.type) + (r == 0) && + (ofile == NULL || + apk_checksum_compare(&ofile->csum, &fi.csum) == 0)) { + /* Protected directory, with file without + * db entry, or local modifications. + * + * Delete the apk-new if it's identical with the + * existing file */ + if (ofile == NULL || + ofile->csum.type != file->csum.type) apk_file_get_info(name, file->csum.type, &fi); if (apk_checksum_compare(&file->csum, &fi.csum) == 0) unlink(tmpname); @@ -1504,32 +1511,6 @@ static void apk_db_migrate_files(struct apk_database *db, } } -#if 0 - if ((diri->dir->flags & APK_DBDIRF_PROTECTED) && - apk_file_get_info(ae->name, file->csum.type, &fi) == 0 && - apk_checksum_compare(&file->csum, &fi.csum) != 0) { - /* Protected file. Extract to separate place */ - if (!(apk_flags & APK_CLEAN_PROTECTED)) { - snprintf(alt_name, sizeof(alt_name), - "%s/%s.apk-new", - diri->dir->name, file->name); - r = apk_archive_entry_extract(ae, is, alt_name, - extract_cb, ctx); - - /* remove identical apk-new */ - if (ae->csum.type != fi.csum.type) - apk_file_get_info(ae->name, ae->csum.type, &fi); - if (apk_checksum_compare(&ae->csum, &fi.csum) == 0) - unlink(alt_name); - } - } else { - r = apk_archive_entry_extract(ae, is, NULL, - extract_cb, ctx); - } - memcpy(&file->csum, &ae->csum, sizeof(file->csum)); -#endif - - static int apk_db_unpack_pkg(struct apk_database *db, struct apk_package *newpkg, int upgrade, apk_progress_cb cb, void *cb_ctx) |