rm-rf: Reduce transitive includes

This commit is contained in:
Daan De Meyer
2025-05-05 14:13:11 +02:00
committed by Yu Watanabe
parent b78d73fa22
commit dc7b151264
10 changed files with 44 additions and 29 deletions

View File

@@ -1,5 +1,6 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#include "alloc-util.h"
#include "analyze.h"
#include "analyze-verify.h"
#include "analyze-verify-util.h"

View File

@@ -2,6 +2,7 @@
#include <unistd.h>
#include "errno-util.h"
#include "generator-setup.h"
#include "macro.h"
#include "mkdir-label.h"

View File

@@ -6,6 +6,7 @@
#include "alloc-util.h"
#include "btrfs-util.h"
#include "copy.h"
#include "errno-util.h"
#include "fd-util.h"
#include "fileio.h"
#include "fs-util.h"

View File

@@ -9,6 +9,7 @@
#include "btrfs-util.h"
#include "copy.h"
#include "curl-util.h"
#include "errno-util.h"
#include "fd-util.h"
#include "fs-util.h"
#include "hostname-util.h"

View File

@@ -3,6 +3,7 @@
#include <sys/eventfd.h>
#include <sys/mount.h>
#include "errno-util.h"
#include "fd-util.h"
#include "log.h"
#include "main-func.h"

View File

@@ -3,7 +3,9 @@
#include "sd-json.h"
#include "sd-netlink.h"
#include "alloc-util.h"
#include "chase.h"
#include "errno-util.h"
#include "fd-util.h"
#include "fileio.h"
#include "format-util.h"

View File

@@ -21,6 +21,7 @@
#include "chase.h"
#include "chattr-util.h"
#include "copy.h"
#include "errno-util.h"
#include "fd-util.h"
#include "fileio.h"
#include "fs-util.h"

View File

@@ -17,6 +17,7 @@
#include "chattr-util.h"
#include "copy.h"
#include "dirent-util.h"
#include "errno-util.h"
#include "fd-util.h"
#include "fileio.h"
#include "fs-util.h"

View File

@@ -9,6 +9,7 @@
#include "alloc-util.h"
#include "btrfs-util.h"
#include "dirent-util.h"
#include "errno-util.h"
#include "fd-util.h"
#include "fs-util.h"
#include "log.h"
@@ -517,3 +518,33 @@ int rm_rf_child(int fd, const char *name, RemoveFlags flags) {
return rm_rf_inner_child(fd, name, -1, flags, NULL, true);
}
const char* rm_rf_safe(const char *p) {
PROTECT_ERRNO;
if (!p)
return NULL;
(void) rm_rf(p, REMOVE_ROOT|REMOVE_MISSING_OK|REMOVE_CHMOD);
return NULL;
}
char* rm_rf_physical_and_free(char *p) {
PROTECT_ERRNO;
if (!p)
return NULL;
(void) rm_rf(p, REMOVE_ROOT|REMOVE_PHYSICAL|REMOVE_MISSING_OK|REMOVE_CHMOD);
return mfree(p);
}
char* rm_rf_subvolume_and_free(char *p) {
PROTECT_ERRNO;
if (!p)
return NULL;
(void) rm_rf(p, REMOVE_ROOT|REMOVE_PHYSICAL|REMOVE_SUBVOLUME|REMOVE_MISSING_OK|REMOVE_CHMOD);
return mfree(p);
}

View File

@@ -4,8 +4,7 @@
#include <fcntl.h>
#include <sys/stat.h>
#include "alloc-util.h"
#include "errno-util.h"
#include "memory-util.h"
typedef enum RemoveFlags {
REMOVE_ONLY_DIRECTORIES = 1 << 0, /* Only remove empty directories, no files */
@@ -35,37 +34,13 @@ static inline int rm_rf(const char *path, RemoveFlags flags) {
}
/* Useful for using with _cleanup_(), destroys a directory on a temporary file system. */
static inline const char* rm_rf_safe(const char *p) {
PROTECT_ERRNO;
if (!p)
return NULL;
(void) rm_rf(p, REMOVE_ROOT|REMOVE_MISSING_OK|REMOVE_CHMOD);
return NULL;
}
const char* rm_rf_safe(const char *p);
DEFINE_TRIVIAL_CLEANUP_FUNC(const char*, rm_rf_safe);
/* Similar as above, but allow to destroy a directory on a physical file system, and also frees the pointer. */
static inline char* rm_rf_physical_and_free(char *p) {
PROTECT_ERRNO;
if (!p)
return NULL;
(void) rm_rf(p, REMOVE_ROOT|REMOVE_PHYSICAL|REMOVE_MISSING_OK|REMOVE_CHMOD);
return mfree(p);
}
char* rm_rf_physical_and_free(char *p);
DEFINE_TRIVIAL_CLEANUP_FUNC(char*, rm_rf_physical_and_free);
/* Similar as above, but also has magic btrfs subvolume powers. */
static inline char* rm_rf_subvolume_and_free(char *p) {
PROTECT_ERRNO;
if (!p)
return NULL;
(void) rm_rf(p, REMOVE_ROOT|REMOVE_PHYSICAL|REMOVE_SUBVOLUME|REMOVE_MISSING_OK|REMOVE_CHMOD);
return mfree(p);
}
char* rm_rf_subvolume_and_free(char *p);
DEFINE_TRIVIAL_CLEANUP_FUNC(char*, rm_rf_subvolume_and_free);