diff options
author | Timo Teräs <timo.teras@iki.fi> | 2023-01-31 15:34:34 +0200 |
---|---|---|
committer | Timo Teräs <timo.teras@iki.fi> | 2023-04-10 22:06:24 +0300 |
commit | efb55ce650d3cac9a607560d840f95c1127e68f5 (patch) | |
tree | 72e5d4f21062af0060a21321022297026a9fa16d | |
parent | 6870c6023ebc1e190e5c06138391a3ae80ff975d (diff) | |
download | apk-tools-efb55ce650d3cac9a607560d840f95c1127e68f5.tar.gz apk-tools-efb55ce650d3cac9a607560d840f95c1127e68f5.tar.bz2 apk-tools-efb55ce650d3cac9a607560d840f95c1127e68f5.tar.xz apk-tools-efb55ce650d3cac9a607560d840f95c1127e68f5.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.c | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/src/database.c b/src/database.c index 04eac61..a4c7f97 100644 --- a/src/database.c +++ b/src/database.c @@ -2078,9 +2078,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); |