// 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;
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) {
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
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;
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;
// 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;
}
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);
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);
*/
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);
}
goto ERROR;
// Remove all files on the filelist
- r = pakfire_filelist_cleanup(filelist);
+ r = pakfire_filelist_cleanup(filelist, 0);
if (r)
goto ERROR;