diff options
Diffstat (limited to 'src/shared')
-rw-r--r-- | src/shared/mkdir.c | 15 | ||||
-rw-r--r-- | src/shared/mkdir.h | 2 |
2 files changed, 11 insertions, 6 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; diff --git a/src/shared/mkdir.h b/src/shared/mkdir.h index f1bf4c0a68..d15ede6064 100644 --- a/src/shared/mkdir.h +++ b/src/shared/mkdir.h @@ -41,4 +41,4 @@ typedef int (*mkdir_func_t)(const char *pathname, mode_t mode); int mkdir_safe_internal(const char *path, mode_t mode, uid_t uid, gid_t gid, mkdir_func_t _mkdir); int mkdir_parents_internal(const char *prefix, const char *path, mode_t mode, mkdir_func_t _mkdir); int mkdir_p_internal(const char *prefix, const char *path, mode_t mode, mkdir_func_t _mkdir); -int is_dir(const char *path); +int is_dir(const char *path, bool is_dir); |