summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimo Teräs <timo.teras@iki.fi>2023-01-31 15:34:34 +0200
committerTimo Teräs <timo.teras@iki.fi>2023-01-31 15:34:34 +0200
commit6b92da350bfb310e4e0ccfea8e870be476b9c1d7 (patch)
tree69cf9728ac2aadef9e61f481a1df20e83cd5bce5
parentcf468e297b73b034eb20f867bee5206c93436754 (diff)
downloadapk-tools-6b92da350bfb310e4e0ccfea8e870be476b9c1d7.tar.gz
apk-tools-6b92da350bfb310e4e0ccfea8e870be476b9c1d7.tar.bz2
apk-tools-6b92da350bfb310e4e0ccfea8e870be476b9c1d7.tar.xz
apk-tools-6b92da350bfb310e4e0ccfea8e870be476b9c1d7.zip
cache: fix handling of explict cache at static cache location
Omit separate static cache handling step if the explicit cache is configured to the static cache directory. fixes 609fd218 "cache: fix 'clean' to prune static cache always"
-rw-r--r--src/database.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/src/database.c b/src/database.c
index 1e34cf9..14dff47 100644
--- a/src/database.c
+++ b/src/database.c
@@ -2171,9 +2171,17 @@ int apk_db_cache_foreach_item(struct apk_database *db, apk_cache_item_cb cb, int
struct foreach_cache_item_ctx ctx = { db, cb, static_cache };
if (static_cache) {
- return apk_dir_foreach_file(
- openat(db->root_fd, apk_static_cache_dir, O_RDONLY | O_CLOEXEC),
- foreach_cache_file, &ctx);
+ struct stat st1, st2;
+ int fd = openat(db->root_fd, apk_static_cache_dir, O_RDONLY | O_CLOEXEC);
+ if (fd < 0) return fd;
+ /* Do not handle static cache as static cache if the explicit
+ * cache is enabled at the static cache location */
+ if (fstat(fd, &st1) == 0 && fstat(db->cache_fd, &st2) == 0 &&
+ st1.st_dev == st2.st_dev && st1.st_ino == st2.st_ino) {
+ close(fd);
+ return 0;
+ }
+ return apk_dir_foreach_file(fd, foreach_cache_file, &ctx);
}
if (db->cache_fd < 0) return db->cache_fd;
return apk_dir_foreach_file(dup(db->cache_fd), foreach_cache_file, &ctx);