diff options
author | Timo Teräs <timo.teras@iki.fi> | 2023-01-31 14:44:26 +0200 |
---|---|---|
committer | Timo Teräs <timo.teras@iki.fi> | 2023-04-10 22:06:24 +0300 |
commit | c1db6b2238c728aee982fd65ef7037d6489c3084 (patch) | |
tree | 70b90cabaa54cb9d88fdde4531e8d32cb974f3c7 /src/database.c | |
parent | d351992ad529dccb95fc1c8997cd328e9c694a92 (diff) | |
download | apk-tools-c1db6b2238c728aee982fd65ef7037d6489c3084.tar.gz apk-tools-c1db6b2238c728aee982fd65ef7037d6489c3084.tar.bz2 apk-tools-c1db6b2238c728aee982fd65ef7037d6489c3084.tar.xz apk-tools-c1db6b2238c728aee982fd65ef7037d6489c3084.zip |
cache: fix 'clean' to prune static cache always
Fix cache applet to prune the static cache which is used for index
files if explicit caching is not enabled.
fixes #10754
Diffstat (limited to 'src/database.c')
-rw-r--r-- | src/database.c | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/src/database.c b/src/database.c index 7118c64..04eac61 100644 --- a/src/database.c +++ b/src/database.c @@ -1391,7 +1391,7 @@ static char *find_mountpoint(int atfd, const char *rel_path) return ret; } -static void mark_in_cache(struct apk_database *db, int dirfd, const char *name, struct apk_package *pkg) +static void mark_in_cache(struct apk_database *db, int static_cache, int dirfd, const char *name, struct apk_package *pkg) { if (pkg == NULL) return; @@ -1722,7 +1722,7 @@ int apk_db_open(struct apk_database *db, struct apk_db_options *dbopts) } if (apk_db_cache_active(db) && (dbopts->open_flags & (APK_OPENF_NO_REPOS|APK_OPENF_NO_INSTALLED)) == 0) - apk_db_cache_foreach_item(db, mark_in_cache); + apk_db_cache_foreach_item(db, mark_in_cache, 0); db->open_complete = 1; @@ -2038,6 +2038,7 @@ int apk_db_cache_active(struct apk_database *db) struct foreach_cache_item_ctx { struct apk_database *db; apk_cache_item_cb cb; + int static_cache; }; static int foreach_cache_file(void *pctx, int dirfd, const char *name) @@ -2067,15 +2068,21 @@ static int foreach_cache_file(void *pctx, int dirfd, const char *name) } } no_pkg: - ctx->cb(db, dirfd, name, pkg); + ctx->cb(db, ctx->static_cache, dirfd, name, pkg); return 0; } -int apk_db_cache_foreach_item(struct apk_database *db, apk_cache_item_cb cb) +int apk_db_cache_foreach_item(struct apk_database *db, apk_cache_item_cb cb, int static_cache) { - struct foreach_cache_item_ctx ctx = { db, cb }; + 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); + } + if (db->cache_fd < 0) return db->cache_fd; return apk_dir_foreach_file(dup(db->cache_fd), foreach_cache_file, &ctx); } |