diff options
author | Natanael Copa <ncopa@alpinelinux.org> | 2010-09-22 14:16:18 +0000 |
---|---|---|
committer | Natanael Copa <ncopa@alpinelinux.org> | 2010-09-22 14:34:35 +0000 |
commit | 5c4583a9027de2a26d3bff8b443f7db7f0c37074 (patch) | |
tree | 8832b5fad7f2112ff057fd7a087cdcd1d585b237 /src | |
parent | b4adf7645ff6c14e19682b9ef17e15756c5b0b14 (diff) | |
download | apk-tools-5c4583a9027de2a26d3bff8b443f7db7f0c37074.tar.gz apk-tools-5c4583a9027de2a26d3bff8b443f7db7f0c37074.tar.bz2 apk-tools-5c4583a9027de2a26d3bff8b443f7db7f0c37074.tar.xz apk-tools-5c4583a9027de2a26d3bff8b443f7db7f0c37074.zip |
db: optionally remove dirs when unref
We want remove dirs when they are unreferenced so we remove all dirs on
apk del, but we don't want remove dirs when closing database. So we make
removing dir optional when unreferencing it.
This partially reverts commit c7ffc96a16c6963fe0a07be7ee75e8f1f7426882.
fixes #406
Diffstat (limited to 'src')
-rw-r--r-- | src/database.c | 28 |
1 files changed, 15 insertions, 13 deletions
diff --git a/src/database.c b/src/database.c index 925aa4a..0054837 100644 --- a/src/database.c +++ b/src/database.c @@ -30,6 +30,11 @@ #include "apk_archive.h" #include "apk_print.h" +enum { + APK_DISALLOW_RMDIR = 0, + APK_ALLOW_RMDIR = 1 +}; + int apk_verbosity = 1; unsigned int apk_flags = 0; @@ -188,16 +193,19 @@ struct apk_name *apk_db_get_name(struct apk_database *db, apk_blob_t name) return pn; } -static void apk_db_dir_unref(struct apk_database *db, struct apk_db_dir *dir) +static void apk_db_dir_unref(struct apk_database *db, struct apk_db_dir *dir, + int allow_rmdir) { dir->refs--; if (dir->refs > 0) return; db->installed.stats.dirs--; + if (allow_rmdir) + unlinkat(db->root_fd, dir->name, AT_REMOVEDIR); if (dir->parent != NULL) - apk_db_dir_unref(db, dir->parent); + apk_db_dir_unref(db, dir->parent, allow_rmdir); } static struct apk_db_dir *apk_db_dir_ref(struct apk_db_dir *dir) @@ -307,16 +315,11 @@ static void apk_db_diri_mkdir(struct apk_database *db, struct apk_db_dir_instanc } } -static void apk_db_diri_rmdir(struct apk_database *db, struct apk_db_dir_instance *diri) -{ - if (diri->dir->refs == 1) - unlinkat(db->root_fd, diri->dir->name, 1); -} - static void apk_db_diri_free(struct apk_database *db, - struct apk_db_dir_instance *diri) + struct apk_db_dir_instance *diri, + int allow_rmdir) { - apk_db_dir_unref(db, diri->dir); + apk_db_dir_unref(db, diri->dir, allow_rmdir); free(diri); } @@ -1265,7 +1268,7 @@ void apk_db_close(struct apk_database *db) list_for_each_entry(ipkg, &db->installed.packages, installed_pkgs_list) { hlist_for_each_entry_safe(diri, dc, dn, &ipkg->owned_dirs, pkg_dirs_list) { - apk_db_diri_free(db, diri); + apk_db_diri_free(db, diri, APK_DISALLOW_RMDIR); } } @@ -1884,9 +1887,8 @@ static void apk_db_purge_pkg(struct apk_database *db, db->installed.stats.files--; } } - apk_db_diri_rmdir(db, diri); __hlist_del(dc, &ipkg->owned_dirs.first); - apk_db_diri_free(db, diri); + apk_db_diri_free(db, diri, APK_ALLOW_RMDIR); } } |