tmpfiles: introduce empty_directory()
This commit is contained in:
parent
4c39d899ff
commit
5494602195
|
@ -866,40 +866,15 @@ static int path_open_parent_safe(const char *path) {
|
||||||
|
|
||||||
static int path_set_perms(Item *i, const char *path) {
|
static int path_set_perms(Item *i, const char *path) {
|
||||||
_cleanup_close_ int fd = -1;
|
_cleanup_close_ int fd = -1;
|
||||||
struct stat stbuf, *st = NULL;
|
|
||||||
|
|
||||||
assert(i);
|
assert(i);
|
||||||
assert(path);
|
assert(path);
|
||||||
|
|
||||||
fd = open(path, O_NOFOLLOW|O_CLOEXEC|O_PATH);
|
fd = open(path, O_NOFOLLOW|O_CLOEXEC|O_PATH);
|
||||||
if (fd < 0) {
|
if (fd < 0)
|
||||||
int level = LOG_ERR, r = -errno;
|
return log_error_errno(errno, "Failed to open \"%s\" to adjust permissions: %m", path);
|
||||||
|
|
||||||
/* Option "e" operates only on existing objects. Do not
|
return fd_set_perms(i, fd, NULL);
|
||||||
* print errors about non-existent files or directories */
|
|
||||||
if (i->type == EMPTY_DIRECTORY && errno == ENOENT) {
|
|
||||||
level = LOG_DEBUG;
|
|
||||||
r = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
log_full_errno(level, errno, "Adjusting owner and mode for %s failed: %m", path);
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (i->type == EMPTY_DIRECTORY) {
|
|
||||||
/* FIXME: introduce fd_is_dir() helper ? */
|
|
||||||
if (fstat(fd, &stbuf) < 0)
|
|
||||||
return log_error_errno(errno, "Failed to fstat() file %s: %m", path);
|
|
||||||
|
|
||||||
if (!S_ISDIR(stbuf.st_mode)) {
|
|
||||||
log_error("'%s' already exists and is not a directory. ", path);
|
|
||||||
return -EEXIST;
|
|
||||||
}
|
|
||||||
|
|
||||||
st = &stbuf;
|
|
||||||
}
|
|
||||||
|
|
||||||
return fd_set_perms(i, fd, st);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int parse_xattrs_from_arg(Item *i) {
|
static int parse_xattrs_from_arg(Item *i) {
|
||||||
|
@ -1642,6 +1617,29 @@ static int create_subvolume(Item *i, const char *path) {
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int empty_directory(Item *i, const char *path) {
|
||||||
|
int r;
|
||||||
|
|
||||||
|
assert(i);
|
||||||
|
assert(i->type == EMPTY_DIRECTORY);
|
||||||
|
|
||||||
|
r = is_dir(path, false);
|
||||||
|
if (r == -ENOENT) {
|
||||||
|
/* Option "e" operates only on existing objects. Do not
|
||||||
|
* print errors about non-existent files or directories */
|
||||||
|
log_debug("Skipping missing directory: %s", path);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if (r < 0)
|
||||||
|
return log_error_errno(r, "is_dir() failed on path %s: %m", path);
|
||||||
|
if (r == 0) {
|
||||||
|
log_error("'%s' already exists and is not a directory.", path);
|
||||||
|
return -EEXIST;
|
||||||
|
}
|
||||||
|
|
||||||
|
return path_set_perms(i, path);
|
||||||
|
}
|
||||||
|
|
||||||
static int create_device(Item *i, mode_t file_type) {
|
static int create_device(Item *i, mode_t file_type) {
|
||||||
_cleanup_close_ int dfd = -1, fd = -1;
|
_cleanup_close_ int dfd = -1, fd = -1;
|
||||||
CreationMode creation;
|
CreationMode creation;
|
||||||
|
@ -1901,7 +1899,7 @@ static int create_item(Item *i) {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case EMPTY_DIRECTORY:
|
case EMPTY_DIRECTORY:
|
||||||
r = glob_item(i, path_set_perms);
|
r = glob_item(i, empty_directory);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in a new issue