summaryrefslogtreecommitdiff
path: root/src/shared/mkdir.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/shared/mkdir.c')
-rw-r--r--src/shared/mkdir.c15
1 files changed, 10 insertions, 5 deletions
diff --git a/src/shared/mkdir.c b/src/shared/mkdir.c
index ba083d6d67..f941efb401 100644
--- a/src/shared/mkdir.c
+++ b/src/shared/mkdir.c
@@ -58,11 +58,16 @@ int mkdir_safe(const char *path, mode_t mode, uid_t uid, gid_t gid) {
return mkdir_safe_internal(path, mode, uid, gid, mkdir);
}
-int is_dir(const char* path) {
+int is_dir(const char* path, bool follow) {
struct stat st;
- if (stat(path, &st) < 0)
- return -errno;
+ if (follow) {
+ if (stat(path, &st) < 0)
+ return -errno;
+ } else {
+ if (lstat(path, &st) < 0)
+ return -errno;
+ }
return S_ISDIR(st.st_mode);
}
@@ -85,7 +90,7 @@ int mkdir_parents_internal(const char *prefix, const char *path, mode_t mode, mk
return 0;
p = strndupa(path, e - path);
- r = is_dir(p);
+ r = is_dir(p, true);
if (r > 0)
return 0;
if (r == 0)
@@ -130,7 +135,7 @@ int mkdir_p_internal(const char *prefix, const char *path, mode_t mode, mkdir_fu
return r;
r = _mkdir(path, mode);
- if (r < 0 && (errno != EEXIST || is_dir(path) <= 0))
+ if (r < 0 && (errno != EEXIST || is_dir(path, true) <= 0))
return -errno;
return 0;