homework: replace homegrown "dir-is-empty" check with dir_is_empty_at()
This commit is contained in:
committed by
Yu Watanabe
parent
b1ccd7d737
commit
1845ba368e
@@ -9,6 +9,7 @@
|
||||
#include "homework-mount.h"
|
||||
#include "mount-util.h"
|
||||
#include "process-util.h"
|
||||
#include "stat-util.h"
|
||||
#include "strv.h"
|
||||
#include "tmpfile-util.h"
|
||||
|
||||
@@ -143,8 +144,6 @@ int home_activate_cifs(
|
||||
|
||||
int home_create_cifs(UserRecord *h, HomeSetup *setup, UserRecord **ret_home) {
|
||||
_cleanup_(user_record_unrefp) UserRecord *new_home = NULL;
|
||||
_cleanup_(closedirp) DIR *d = NULL;
|
||||
_cleanup_close_ int copy = -1;
|
||||
int r;
|
||||
|
||||
assert(h);
|
||||
@@ -166,19 +165,11 @@ int home_create_cifs(UserRecord *h, HomeSetup *setup, UserRecord **ret_home) {
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
copy = fcntl(setup->root_fd, F_DUPFD_CLOEXEC, 3);
|
||||
if (copy < 0)
|
||||
return -errno;
|
||||
|
||||
d = take_fdopendir(©);
|
||||
if (!d)
|
||||
return -errno;
|
||||
|
||||
errno = 0;
|
||||
if (readdir_no_dot(d))
|
||||
r = dir_is_empty_at(setup->root_fd, NULL);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to detect if CIFS directory is empty: %m");
|
||||
if (r == 0)
|
||||
return log_error_errno(SYNTHETIC_ERRNO(ENOTEMPTY), "Selected CIFS directory not empty, refusing.");
|
||||
if (errno != 0)
|
||||
return log_error_errno(errno, "Failed to detect if CIFS directory is empty: %m");
|
||||
|
||||
r = home_populate(h, setup->root_fd);
|
||||
if (r < 0)
|
||||
|
||||
Reference in New Issue
Block a user