summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTimo Teras <timo.teras@iki.fi>2009-07-22 21:34:25 +0300
committerTimo Teras <timo.teras@iki.fi>2009-07-22 21:34:25 +0300
commit90aaa28a95f28206e6bf4ed0d5a798595165cb8c (patch)
tree67071fbc48be4d3748faf55b5570d197003c4652 /src
parent83ae16feb8bb6063ac26eb4cbbc6142bfb4057a4 (diff)
downloadapk-tools-90aaa28a95f28206e6bf4ed0d5a798595165cb8c.tar.gz
apk-tools-90aaa28a95f28206e6bf4ed0d5a798595165cb8c.tar.bz2
apk-tools-90aaa28a95f28206e6bf4ed0d5a798595165cb8c.tar.xz
apk-tools-90aaa28a95f28206e6bf4ed0d5a798595165cb8c.zip
apk: add --purge option (fixes #61)
and do not remove modified configuration files unless --purge is specified.
Diffstat (limited to 'src')
-rw-r--r--src/apk.c5
-rw-r--r--src/apk_defines.h1
-rw-r--r--src/database.c7
3 files changed, 12 insertions, 1 deletions
diff --git a/src/apk.c b/src/apk.c
index 5266158..89dd53d 100644
--- a/src/apk.c
+++ b/src/apk.c
@@ -43,6 +43,8 @@ static struct apk_option generic_options[] = {
{ 0x101, "progress", "Show a progress bar" },
{ 0x102, "clean-protected", "Do not create .apk-new files to "
"configuration dirs" },
+ { 0x106, "purge", "Delete also modified configuration files on "
+ "package removal" },
{ 0x103, "allow-untrusted", "Blindly install packages with untrusted "
"signatures or no signature at all" },
{ 0x104, "simulate", "Show what would be done without actually "
@@ -359,6 +361,9 @@ int main(int argc, char **argv)
case 0x104:
apk_flags |= APK_SIMULATE;
break;
+ case 0x106:
+ apk_flags |= APK_PURGE;
+ break;
case 0x105:
apk_wait = atoi(optarg);
break;
diff --git a/src/apk_defines.h b/src/apk_defines.h
index 7e66ada..a7e13f9 100644
--- a/src/apk_defines.h
+++ b/src/apk_defines.h
@@ -60,6 +60,7 @@ extern unsigned int apk_flags;
#define APK_PREFER_AVAILABLE 0x0040
#define APK_UPDATE_CACHE 0x0080
#define APK_ALLOW_UNTRUSTED 0x0100
+#define APK_PURGE 0x0200
#define apk_error(args...) do { apk_log("ERROR: ", args); } while (0)
#define apk_warning(args...) do { if (apk_verbosity > 0) { apk_log("WARNING: ", args); } } while (0)
diff --git a/src/database.c b/src/database.c
index e171ca9..719a445 100644
--- a/src/database.c
+++ b/src/database.c
@@ -1425,6 +1425,7 @@ static void apk_db_purge_pkg(struct apk_database *db, struct apk_package *pkg,
struct apk_db_dir_instance *diri;
struct apk_db_file *file;
struct apk_db_file_hash_key key;
+ struct apk_file_info fi;
struct hlist_node *dc, *dn, *fc, *fn;
unsigned long hash;
char name[1024];
@@ -1439,7 +1440,11 @@ static void apk_db_purge_pkg(struct apk_database *db, struct apk_package *pkg,
.filename = APK_BLOB_PTR_LEN(file->name, file->namelen),
};
hash = apk_blob_hash_seed(key.filename, diri->dir->hash);
- unlink(name);
+ if (!(diri->dir->flags & APK_DBDIRF_PROTECTED) ||
+ (apk_flags & APK_PURGE) ||
+ (apk_file_get_info(name, file->csum.type, &fi) == 0 &&
+ apk_checksum_compare(&file->csum, &fi.csum) == 0))
+ unlink(name);
if (apk_verbosity > 1)
printf("%s\n", name);
__hlist_del(fc, &diri->owned_files.first);