From: Michael Tremer Date: Fri, 24 Mar 2023 16:09:32 +0000 (+0000) Subject: file: Make the _cleanup function configurable to tidy up as well X-Git-Tag: 0.9.29~217 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=9274236e83d44e1d520b426fc2ed57375a37c98b;p=pakfire.git file: Make the _cleanup function configurable to tidy up as well Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/build.c b/src/libpakfire/build.c index 267c9df05..a5653a30f 100644 --- a/src/libpakfire/build.c +++ b/src/libpakfire/build.c @@ -1056,7 +1056,7 @@ static int pakfire_build_post_process_files(struct pakfire_build* build, // Remove all files on the removee list if (flags & PAKFIRE_BUILD_CLEANUP_FILES) { - r = pakfire_filelist_cleanup(removees); + r = pakfire_filelist_cleanup(removees, PAKFIRE_FILE_CLEANUP_TIDY); if (r) goto ERROR; diff --git a/src/libpakfire/file.c b/src/libpakfire/file.c index 47ad18fab..33e26fea8 100644 --- a/src/libpakfire/file.c +++ b/src/libpakfire/file.c @@ -1334,7 +1334,7 @@ int pakfire_file_compute_digests(struct pakfire_file* file, const int types) { return __pakfire_file_compute_digests(file, &file->digests, types); } -int pakfire_file_remove(struct pakfire_file* file) { +static int pakfire_file_remove(struct pakfire_file* file) { int r; if (!*file->abspath) { @@ -1651,7 +1651,7 @@ int pakfire_file_matches_class(struct pakfire_file* file, const int class) { It will try to delete any parent directories as well and ignore if directories cannot be deleted because they might contain other files */ -int pakfire_file_cleanup(struct pakfire_file* file) { +int pakfire_file_cleanup(struct pakfire_file* file, int flags) { char path[PATH_MAX]; // Try removing the file @@ -1659,29 +1659,32 @@ int pakfire_file_cleanup(struct pakfire_file* file) { if (r) return r; - // Create a working copy of abspath - r = pakfire_string_set(path, file->abspath); - if (r) - return r; + // Try to tidy up afterwards + if (flags & PAKFIRE_FILE_CLEANUP_TIDY) { + // Create a working copy of abspath + r = pakfire_string_set(path, file->abspath); + if (r) + return r; - // See how many levels this file has - int levels = pakfire_file_levels(file); + // See how many levels this file has + int levels = pakfire_file_levels(file); - // Walk all the way up and remove all parent directories if possible - while (--levels) { - dirname(path); + // Walk all the way up and remove all parent directories if possible + while (--levels) { + dirname(path); - // Break if path is suddenly empty - if (!*path) - break; + // Break if path is suddenly empty + if (!*path) + break; - DEBUG(file->pakfire, "Trying to remove parent directory %s\n", path); + DEBUG(file->pakfire, "Trying to remove parent directory %s\n", path); - r = rmdir(path); + r = rmdir(path); - // Break on any error - if (r) - break; + // Break on any error + if (r) + break; + } } return 0; diff --git a/src/libpakfire/filelist.c b/src/libpakfire/filelist.c index c76c34e4e..d33b62a01 100644 --- a/src/libpakfire/filelist.c +++ b/src/libpakfire/filelist.c @@ -584,7 +584,7 @@ ERROR: return r; } -int pakfire_filelist_cleanup(struct pakfire_filelist* list) { +int pakfire_filelist_cleanup(struct pakfire_filelist* list, int flags) { struct pakfire_filelist_element* element = NULL; int r; @@ -594,7 +594,7 @@ int pakfire_filelist_cleanup(struct pakfire_filelist* list) { // Walk through the list backwards TAILQ_FOREACH_REVERSE(element, &list->files, entries, nodes) { - r = pakfire_file_cleanup(element->file); + r = pakfire_file_cleanup(element->file, flags); if (r) return r; } diff --git a/src/libpakfire/include/pakfire/file.h b/src/libpakfire/include/pakfire/file.h index 7508f32d4..8030fae78 100644 --- a/src/libpakfire/include/pakfire/file.h +++ b/src/libpakfire/include/pakfire/file.h @@ -167,8 +167,10 @@ int pakfire_file_payload_matches(struct pakfire_file* file, int pakfire_file_compute_digests(struct pakfire_file* file, const int types); -int pakfire_file_remove(struct pakfire_file* file); -int pakfire_file_cleanup(struct pakfire_file* file); +enum pakfire_file_cleanup_flags { + PAKFIRE_FILE_CLEANUP_TIDY = (1 << 0), +}; +int pakfire_file_cleanup(struct pakfire_file* file, int flags); int pakfire_file_symlink_target_exists(struct pakfire_file* file); diff --git a/src/libpakfire/include/pakfire/filelist.h b/src/libpakfire/include/pakfire/filelist.h index 3114f9923..1ae3fd05b 100644 --- a/src/libpakfire/include/pakfire/filelist.h +++ b/src/libpakfire/include/pakfire/filelist.h @@ -65,7 +65,7 @@ int pakfire_filelist_dump(struct pakfire_filelist* list, int flags); int pakfire_filelist_verify(struct pakfire_filelist* list, struct pakfire_filelist* errors); -int pakfire_filelist_cleanup(struct pakfire_filelist* list); +int pakfire_filelist_cleanup(struct pakfire_filelist* list, int flags); int pakfire_filelist_matches_class(struct pakfire_filelist* list, int class); diff --git a/src/libpakfire/packager.c b/src/libpakfire/packager.c index 04b41436a..21a812b93 100644 --- a/src/libpakfire/packager.c +++ b/src/libpakfire/packager.c @@ -667,5 +667,5 @@ int pakfire_packager_add_scriptlet(struct pakfire_packager* packager, */ int pakfire_packager_cleanup(struct pakfire_packager* packager) { // Delete all files on the filelist - return pakfire_filelist_cleanup(packager->filelist); + return pakfire_filelist_cleanup(packager->filelist, PAKFIRE_FILE_CLEANUP_TIDY); } diff --git a/src/libpakfire/transaction.c b/src/libpakfire/transaction.c index 160c74aaa..6852259fc 100644 --- a/src/libpakfire/transaction.c +++ b/src/libpakfire/transaction.c @@ -751,7 +751,7 @@ static int pakfire_transaction_erase(struct pakfire_transaction* transaction, goto ERROR; // Remove all files on the filelist - r = pakfire_filelist_cleanup(filelist); + r = pakfire_filelist_cleanup(filelist, 0); if (r) goto ERROR;