summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Rees <maxcrees@me.com>2019-08-10 02:08:10 -0500
committerA. Wilcox <AWilcox@Wilcox-Tech.com>2023-11-29 22:04:30 -0600
commitf233ecb4897b14ad868152c76bcd9b3f566c0a22 (patch)
tree5a0147060ccf05d32d16365f132cd647725ade89
parent2cd22bd777a87629791416f7a807ea483ace44ce (diff)
downloadapk-tools-f233ecb4897b14ad868152c76bcd9b3f566c0a22.tar.gz
apk-tools-f233ecb4897b14ad868152c76bcd9b3f566c0a22.tar.bz2
apk-tools-f233ecb4897b14ad868152c76bcd9b3f566c0a22.tar.xz
apk-tools-f233ecb4897b14ad868152c76bcd9b3f566c0a22.zip
cache: report errors when unlinking
Before: $ abuild-apk del mutt (1/3) Purging mutt (1.12.1-r0) (2/3) Purging gdbm (1.18.1-r0) (3/3) Purging libidn (1.35-r0) OK: 3752 MiB in 805 packages $ apk cache sync --purge || echo nope, sorry $ ls /home/apk-cache/*gdbm* /home/apk-cache/gdbm-1.18.1-r0.b0b17e93.apk After: $ apk cache sync --purge || echo nope, sorry ERROR: Unable to delete gdbm-1.18.1-r0.b0b17e93.apk: Permission denied nope, sorry
-rw-r--r--src/apk_database.h2
-rw-r--r--src/app_cache.c16
-rw-r--r--src/database.c9
3 files changed, 17 insertions, 10 deletions
diff --git a/src/apk_database.h b/src/apk_database.h
index da29ce9..92a6fbd 100644
--- a/src/apk_database.h
+++ b/src/apk_database.h
@@ -277,7 +277,7 @@ int apk_cache_download(struct apk_database *db, struct apk_repository *repo,
struct apk_package *pkg, int verify, int autoupdate,
apk_progress_cb cb, void *cb_ctx);
-typedef void (*apk_cache_item_cb)(struct apk_database *db, int static_cache,
+typedef int (*apk_cache_item_cb)(struct apk_database *db, int static_cache,
int dirfd, const char *name,
struct apk_package *pkg);
int apk_db_cache_foreach_item(struct apk_database *db, apk_cache_item_cb cb, int static_cache);
diff --git a/src/app_cache.c b/src/app_cache.c
index f40c836..61f386f 100644
--- a/src/app_cache.c
+++ b/src/app_cache.c
@@ -13,6 +13,7 @@
#include <dirent.h>
#include <unistd.h>
#include <limits.h>
+#include <string.h>
#include "apk_defines.h"
#include "apk_applet.h"
@@ -142,7 +143,7 @@ static int cache_download(struct cache_ctx *cctx, struct apk_database *db, struc
return ret;
}
-static void cache_clean_item(struct apk_database *db, int static_cache, int dirfd, const char *name, struct apk_package *pkg)
+static int cache_clean_item(struct apk_database *db, int static_cache, int dirfd, const char *name, struct apk_package *pkg)
{
char tmp[PATH_MAX];
apk_blob_t b;
@@ -164,16 +165,23 @@ static void cache_clean_item(struct apk_database *db, int static_cache, int dirf
for (i = 0; i < db->num_repos; i++) {
/* Check if this is a valid index */
apk_repo_format_cache_index(APK_BLOB_BUF(tmp), &db->repos[i]);
- if (apk_blob_compare(b, APK_BLOB_STR(tmp)) == 0) return;
+ if (apk_blob_compare(b, APK_BLOB_STR(tmp)) == 0) return 0;
}
delete:
if (apk_verbosity >= 2)
apk_message("deleting %s", name);
if (!(apk_flags & APK_SIMULATE)) {
- if (unlinkat(dirfd, name, 0) < 0 && errno == EISDIR)
- unlinkat(dirfd, name, AT_REMOVEDIR);
+ if (unlinkat(dirfd, name, 0) < 0) {
+ if (errno != EISDIR ||
+ (errno == EISDIR && unlinkat(dirfd, name, AT_REMOVEDIR) < 0)) {
+ apk_error("Unable to delete %s: %s", name, strerror(errno));
+ return -errno;
+ }
+ }
}
+
+ return 0;
}
static int cache_clean(struct apk_database *db)
diff --git a/src/database.c b/src/database.c
index d0ab6e2..9939573 100644
--- a/src/database.c
+++ b/src/database.c
@@ -1367,12 +1367,13 @@ static char *find_mountpoint(int atfd, const char *rel_path)
return ret;
}
-static void mark_in_cache(struct apk_database *db, int static_cache, int dirfd, const char *name, struct apk_package *pkg)
+static int mark_in_cache(struct apk_database *db, int static_cache, int dirfd, const char *name, struct apk_package *pkg)
{
if (pkg == NULL)
- return;
+ return 0;
pkg->repos |= BIT(APK_REPOSITORY_CACHED);
+ return 0;
}
static int add_repos_from_file(void *ctx, int dirfd, const char *file)
@@ -2052,9 +2053,7 @@ static int foreach_cache_file(void *pctx, int dirfd, const char *name)
}
}
no_pkg:
- ctx->cb(db, ctx->static_cache, dirfd, name, pkg);
-
- return 0;
+ return ctx->cb(db, dirfd, name, pkg);
}
int apk_db_cache_foreach_item(struct apk_database *db, apk_cache_item_cb cb, int static_cache)