mirror of
https://github.com/troglobit/finit.git
synced 2026-10-16 10:39:35 +00:00
util: promote rmrf() from tmpfiles.c, fix silent mksubsys() skip
rmrf() is needed outside tmpfiles.c. The move also deduplicates the nftw callback: the contents-only removal used by tmpfiles 'D' entries is now rmcontents(), sharing the callback with rmrf(). mksubsys() did nothing at all when the user could not be resolved, no directory and no message, and callers had no way to tell. Now the directory is always created, ownership is best effort, and an unknown user is warned about. Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
3 files changed
+46
-34
No files matched your search
+1
-30
@@ -130,33 +130,6 @@ static int parse_mm(char *arg, int *major, int *minor)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int do_delete(const char *fpath, const struct stat *sb, int tflag, struct FTW *ftw)
|
||||
{
|
||||
(void)sb;
|
||||
(void)tflag;
|
||||
|
||||
if (ftw->level == 0)
|
||||
return 1;
|
||||
|
||||
if (remove(fpath) && errno != EBUSY)
|
||||
warn("Failed removing %s", fpath);
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
static int rmrf(const char *path)
|
||||
{
|
||||
if (!fisdir(path))
|
||||
return 0;
|
||||
|
||||
nftw(path, do_delete, 20, FTW_DEPTH | FTW_PHYS);
|
||||
if (remove(path) && errno != ENOENT)
|
||||
warn("Failed removing path %s", path);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void mkparent(char *path, mode_t mode)
|
||||
{
|
||||
mkpath(dirname(strdupa(path)), mode);
|
||||
@@ -465,9 +438,7 @@ static void tmpfiles(char *line)
|
||||
case 'd':
|
||||
break;
|
||||
case 'D':
|
||||
if (fisdir(path)) {
|
||||
nftw(path, do_delete, 20, FTW_DEPTH | FTW_PHYS);
|
||||
}
|
||||
rmcontents(path);
|
||||
break;
|
||||
case 'e':
|
||||
case 'f':
|
||||
|
||||
Reference in new issue
Block a user