diff common/portpath.c @ 984:faf58e9f518b

Add recursive mkdir and mkdir for windows mkdir for windows is based on the create restricted directory function that was used in nssstore_win
author Andre Heinecke <andre.heinecke@intevation.de>
date Fri, 29 Aug 2014 17:12:35 +0200
parents b3695a3399de
children 66f6361fba1b
line wrap: on
line diff
--- a/common/portpath.c	Fri Aug 29 17:11:35 2014 +0200
+++ b/common/portpath.c	Fri Aug 29 17:12:35 2014 +0200
@@ -6,6 +6,8 @@
  * See LICENSE.txt for details.
  */
 #include "portpath.h"
+#include "strhelp.h"
+#include "util.h"
 
 #include <libgen.h>
 #include <limits.h>
@@ -15,7 +17,6 @@
 #include <sys/types.h>
 #include <unistd.h>
 
-
 char *
 port_dirname(char *path)
 {
@@ -42,9 +43,16 @@
 #ifndef _WIN32
   return mkdir(path, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) == 0;
 #else
-  /* TODO */
-  printf("Should make path: %s\n", path);
-  return false;
+  wchar_t *wchar_path = utf8_to_wchar(path, strlen(path));
+  bool ret;
+
+  if (!wchar_path)
+    {
+      return false;
+    }
+  ret = create_restricted_directory (wchar_path);
+  xfree (wchar_path);
+  return ret;
 #endif
 }
 
@@ -81,7 +89,36 @@
 }
 
 bool
-port_isdir(char *path)
+port_mkdir_p(const char *path)
+{
+  char *parent_path,
+       *p;
+  if (!path) {
+      return false;
+  }
+  if (port_isdir(path)) {
+      return true;
+  }
+  parent_path = xstrndup (path, strlen(path));
+  p = strrchr(parent_path, '/');
+  if (!p)
+    {
+      p = strrchr(parent_path, '\\');
+    }
+  if (!p)
+    {
+      return false;
+    }
+  *p = '\0';
+  if (!port_isdir(parent_path))
+    {
+      port_mkdir_p(parent_path);
+    }
+  return port_mkdir(path);
+}
+
+bool
+port_isdir(const char *path)
 {
   int ret;
 #ifndef _WIN32

http://wald.intevation.org/projects/trustbridge/