summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimo Teräs <timo.teras@iki.fi>2021-11-22 10:33:07 +0200
committerTimo Teräs <timo.teras@iki.fi>2021-11-22 10:35:18 +0200
commitcce62390741f5d2dd62fcb708564b4e00666f65b (patch)
treec9453548cf5875c038bf79e4e34472f85b0ff4fb
parent83b71f0bafeac4b2e7d48cba408014d13a89d614 (diff)
downloadapk-tools-cce62390741f5d2dd62fcb708564b4e00666f65b.tar.gz
apk-tools-cce62390741f5d2dd62fcb708564b4e00666f65b.tar.bz2
apk-tools-cce62390741f5d2dd62fcb708564b4e00666f65b.tar.xz
apk-tools-cce62390741f5d2dd62fcb708564b4e00666f65b.zip
db: fix regression in creating .apk-new files
The apk_fsdir_file_digest() servers dual purpose: to calculate the checksum, but also to determine if the file exists. Move it's error check where it originally was. fixes #10791
-rw-r--r--src/apk_database.h4
-rw-r--r--src/database.c6
2 files changed, 6 insertions, 4 deletions
diff --git a/src/apk_database.h b/src/apk_database.h
index ff94762..5958d6f 100644
--- a/src/apk_database.h
+++ b/src/apk_database.h
@@ -241,7 +241,9 @@ void apk_name_foreach_matching(struct apk_database *db, struct apk_string_array
static inline uint8_t apk_dbf_digest(struct apk_db_file *dbf)
{
- uint8_t alg = apk_digest_alg_by_len(dbf->csum.type);
+ uint8_t alg;
+ if (!dbf) return APK_DIGEST_NONE;
+ alg = apk_digest_alg_by_len(dbf->csum.type);
if (alg == APK_DIGEST_SHA1 && dbf->diri->pkg->ipkg->sha256_160)
alg = APK_DIGEST_SHA256_160;
return alg;
diff --git a/src/database.c b/src/database.c
index 4bb23dd..f31c552 100644
--- a/src/database.c
+++ b/src/database.c
@@ -2658,10 +2658,10 @@ static void apk_db_migrate_files(struct apk_database *db,
if (ofile && ofile->diri->pkg->name == NULL) {
// File was from overlay, delete the package's version
ctrl = APK_FS_CTRL_CANCEL;
- } else if ((diri->dir->protect_mode != APK_PROTECT_NONE) &&
+ } else if (diri->dir->protect_mode != APK_PROTECT_NONE &&
+ apk_fsdir_file_digest(&d, key.filename, apk_dbf_digest(ofile), &dgst) == 0 &&
(!ofile || ofile->csum.type == APK_CHECKSUM_NONE ||
- (apk_fsdir_file_digest(&d, key.filename, apk_dbf_digest(ofile), &dgst) == 0 &&
- apk_digest_cmp_csum(&dgst, &ofile->csum) != 0))) {
+ apk_digest_cmp_csum(&dgst, &ofile->csum) != 0)) {
// Protected directory, and a file without db entry
// or with local modifications. Keep the filesystem file.
// Determine if the package's file should be kept as .apk-new