summaryrefslogtreecommitdiff
path: root/src/database.c
diff options
context:
space:
mode:
authorTimo Teräs <timo.teras@iki.fi>2022-03-28 11:10:03 +0300
committerTimo Teräs <timo.teras@iki.fi>2022-03-29 10:01:34 +0300
commitbc2b5b69b7c016c055e7d25cbfc96b3004e64af2 (patch)
treef4ead66ed8b25529c087e1b1262286673c7db2a7 /src/database.c
parentd0821b6d425ea95778eb3549cec00a3d35ccc3fe (diff)
downloadapk-tools-bc2b5b69b7c016c055e7d25cbfc96b3004e64af2.tar.gz
apk-tools-bc2b5b69b7c016c055e7d25cbfc96b3004e64af2.tar.bz2
apk-tools-bc2b5b69b7c016c055e7d25cbfc96b3004e64af2.tar.xz
apk-tools-bc2b5b69b7c016c055e7d25cbfc96b3004e64af2.zip
db: make --no-cache disable the cache completelytt-no-cache
Including using files found from the cache, or creating the cache directories with --initdb. Based on patch by Paul Spooren.
Diffstat (limited to 'src/database.c')
-rw-r--r--src/database.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/src/database.c b/src/database.c
index 79a5c4a..6758e98 100644
--- a/src/database.c
+++ b/src/database.c
@@ -628,6 +628,7 @@ int apk_repo_format_item(struct apk_database *db, struct apk_repository *repo, s
int *fd, char *buf, size_t len)
{
if (repo->url == db->repos[APK_REPOSITORY_CACHED].url) {
+ if (db->cache_fd < 0) return db->cache_fd;
*fd = db->cache_fd;
return apk_pkg_format_cache_pkg(APK_BLOB_PTR_LEN(buf, len), pkg);
} else {
@@ -651,6 +652,8 @@ int apk_cache_download(struct apk_database *db, struct apk_repository *repo,
int r;
time_t now = time(NULL);
+ if (db->cache_fd < 0) return db->cache_fd;
+
if (pkg != NULL)
r = apk_pkg_format_cache_pkg(APK_BLOB_BUF(cacheitem), pkg);
else
@@ -1664,6 +1667,7 @@ int apk_db_open(struct apk_database *db, struct apk_ctx *ac)
apk_db_setup_repositories(db, ac->cache_dir);
db->root_fd = apk_ctx_fd_root(ac);
+ db->cache_fd = -APKE_CACHE_NOT_AVAILABLE;
db->permanent = !detect_tmpfs_root(db);
if (ac->root && ac->arch) {
@@ -1720,9 +1724,11 @@ int apk_db_open(struct apk_database *db, struct apk_ctx *ac)
add_protected_paths_from_file, db);
/* figure out where to have the cache */
- if ((r = setup_cache(db, ac)) < 0) {
- apk_err(out, "Unable to remount cache read/write");
- goto ret_r;
+ if (!(db->ctx->flags & APK_NO_CACHE)) {
+ if ((r = setup_cache(db, ac)) < 0) {
+ apk_err(out, "Unable to remount cache read/write");
+ goto ret_r;
+ }
}
if (db->ctx->flags & APK_OVERLAY_FROM_STDIN) {
@@ -2116,7 +2122,7 @@ void apk_db_update_directory_permissions(struct apk_database *db)
int apk_db_cache_active(struct apk_database *db)
{
- return db->cache_dir != apk_static_cache_dir;
+ return db->cache_fd > 0 && db->cache_dir != apk_static_cache_dir;
}
struct foreach_cache_item_ctx {
@@ -2160,6 +2166,7 @@ int apk_db_cache_foreach_item(struct apk_database *db, apk_cache_item_cb cb)
{
struct foreach_cache_item_ctx ctx = { db, cb };
+ if (db->cache_fd < 0) return db->cache_fd;
return apk_dir_foreach_file(dup(db->cache_fd), foreach_cache_file, &ctx);
}