chiark
/
gitweb
/
~ianmdlvl
/
elogind.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
| inline |
side by side
(parent:
27407a0
)
shared: fail mkdir_p if the target exists and is not a directory
author
Zbigniew Jędrzejewski-Szmek
<zbyszek@in.waw.pl>
Tue, 2 Oct 2012 12:42:10 +0000
(14:42 +0200)
committer
Zbigniew Jędrzejewski-Szmek
<zbyszek@in.waw.pl>
Tue, 2 Oct 2012 12:56:26 +0000
(14:56 +0200)
This makes mkdir_p actually behave like mkdir -p.
src/shared/mkdir.c
patch
|
blob
|
history
diff --git
a/src/shared/mkdir.c
b/src/shared/mkdir.c
index d654b632ebc69c497406df3a9ec7461404202327..0e51b64f69331d21228b2dcc1621fb29df18f274 100644
(file)
--- a/
src/shared/mkdir.c
+++ b/
src/shared/mkdir.c
@@
-115,6
+115,13
@@
int mkdir_parents_label(const char *path, mode_t mode) {
return makedir_parents(path, mode, true);
}
+static int is_dir(const char* path) {
+ struct stat st;
+ if (stat(path, &st) < 0)
+ return -errno;
+ return S_ISDIR(st.st_mode);
+}
+
static int makedir_p(const char *path, mode_t mode, bool apply) {
int r;
@@
-124,7
+131,8
@@
static int makedir_p(const char *path, mode_t mode, bool apply) {
if (r < 0)
return r;
- if (label_mkdir(path, mode, apply) < 0 && errno != EEXIST)
+ r = label_mkdir(path, mode, apply);
+ if (r < 0 && (errno != EEXIST || is_dir(path) <= 0))
return -errno;
return 0;