summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBernd Wachter <bwachter-tmw@lart.info>2010-03-01 01:05:00 +0100
committerBernd Wachter <bwachter-tmw@lart.info>2010-03-01 01:05:00 +0100
commit56e9e78a8775be791bf1acf203251aa28f0fa0cb (patch)
tree47a5a8d27424e9ee897987d6ea4dd6e043c6bde1
parent23070ec12d1c0ed92c98cc1b424de535f6539abe (diff)
downloadmana-client-56e9e78a8775be791bf1acf203251aa28f0fa0cb.tar.gz
mana-client-56e9e78a8775be791bf1acf203251aa28f0fa0cb.tar.bz2
mana-client-56e9e78a8775be791bf1acf203251aa28f0fa0cb.tar.xz
mana-client-56e9e78a8775be791bf1acf203251aa28f0fa0cb.zip
Handle cases properly where the path already exists, but not as directory
-rw-r--r--src/utils/mkdir.cpp24
1 files changed, 18 insertions, 6 deletions
diff --git a/src/utils/mkdir.cpp b/src/utils/mkdir.cpp
index 223abe71..43f5264e 100644
--- a/src/utils/mkdir.cpp
+++ b/src/utils/mkdir.cpp
@@ -24,10 +24,10 @@
#if defined WIN32
#include <windows.h>
-#else
-#include <sys/stat.h>
#endif
+#include <sys/stat.h>
+
#ifdef _MKDIR_TEST_
// compile with -D_MKDIR_TEST_ to get a standalone binary
#include <cstdio>
@@ -67,12 +67,24 @@ int mkdir_r(const char *pathname) {
*p = '/';
continue;
}
+
+ // check if the name already exists, but not as directory
+ struct stat statbuf;
+ if (!stat(tmp, &statbuf))
+ {
+ if (S_ISDIR(statbuf.st_mode))
+ {
+ *p = '/';
+ continue;
+ }
+ else
+ return -1;
+ }
+
#if defined WIN32
- if (!CreateDirectory(tmp, 0) &&
- GetLastError() != ERROR_ALREADY_EXISTS)
+ if (!CreateDirectory(tmp, 0))
#else
- if (mkdir(tmp, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) &&
- errno != EEXIST)
+ if (mkdir(tmp, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH))
#endif
{
#if defined WIN32