From dac30d50497214c8722a57ee1ae8d3c369babe38 Mon Sep 17 00:00:00 2001 From: Paul Spooren Date: Sat, 3 Oct 2020 12:31:56 -1000 Subject: database: automatically create missing cache dir On some systems the `/var/` dir is mounted in a tmpfs which is reseted after each reboot. For that reason no post-install script can handle the creation of the cache dir at `/var/cache/apk`. Check on database opnening if the folder is available, if not create it. Fixes #10715 Signed-off-by: Paul Spooren --- src/database.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/database.c') diff --git a/src/database.c b/src/database.c index e064ca5..e5d8b86 100644 --- a/src/database.c +++ b/src/database.c @@ -1660,6 +1660,12 @@ int apk_db_open(struct apk_database *db, struct apk_db_options *dbopts) if (fd >= 0) close(fd); db->cache_dir = apk_static_cache_dir; db->cache_fd = openat(db->root_fd, db->cache_dir, O_RDONLY | O_CLOEXEC); + if (db->cache_fd < 0) { + mkdirat(db->root_fd, "var/cache", 0755); + mkdirat(db->root_fd, "var/cache/apk", 0755); + db->cache_fd = openat(db->root_fd, db->cache_dir, O_RDONLY | O_CLOEXEC); + if (db->cache_fd < 0) goto ret_errno; + } } db->keys_fd = openat(db->root_fd, -- cgit v1.2.3-60-g2f50