diff options
Diffstat (limited to 'src/app_cache.c')
-rw-r--r-- | src/app_cache.c | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/src/app_cache.c b/src/app_cache.c index f40c836..5508387 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,21 +143,21 @@ 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; int i; if (!static_cache) { - if (strcmp(name, "installed") == 0) return; + if (strcmp(name, "installed") == 0) return 0; if (pkg) { if (apk_flags & APK_PURGE) { if (db->permanent || !pkg->ipkg) goto delete; } if (pkg->repos & db->local_repos & ~BIT(APK_REPOSITORY_CACHED)) goto delete; if (pkg->ipkg == NULL && !(pkg->repos & ~BIT(APK_REPOSITORY_CACHED))) goto delete; - return; + return 0; } } @@ -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) |