List:Commits« Previous MessageNext Message »
From:Magnus Blåudd Date:September 23 2010 9:02am
Subject:bzr commit into mysql-5.1-telco-7.0 branch (magnus.blaudd:3786)
View as plain text  
#At file:///home/msvensson/mysql/7.0/ based on revid:jonas@stripped

 3786 Magnus Blåudd	2010-09-23
      ndb
       - add support for ignoring create of directory which already exists to NdbDir
       - use the new functionality from atrt which create directories multiple times

    modified:
      storage/ndb/include/portlib/NdbDir.hpp
      storage/ndb/src/common/portlib/NdbDir.cpp
      storage/ndb/test/run-test/files.cpp
=== modified file 'storage/ndb/include/portlib/NdbDir.hpp'
--- a/storage/ndb/include/portlib/NdbDir.hpp	2010-09-23 07:31:51 +0000
+++ b/storage/ndb/include/portlib/NdbDir.hpp	2010-09-23 09:02:47 +0000
@@ -72,13 +72,18 @@ public:
 
   /*
     Create directory
+     path - path to directory to create
+     mode - mode for the directory to create
+     ignore_existing - don't print or return error if directory
+                       already exist
   */
   static bool create(const char *path,
-                     mode_t mode = u_rwx());
+                     mode_t mode = u_rwx(),
+                     bool ignore_existing = false);
 
   /*
     Remove directory recursively
-      dir - path to directory that should be removed
+      path - path to directory that should be removed
       only_contents - only remove the contents of the directory
 
   */

=== modified file 'storage/ndb/src/common/portlib/NdbDir.cpp'
--- a/storage/ndb/src/common/portlib/NdbDir.cpp	2010-09-23 07:31:51 +0000
+++ b/storage/ndb/src/common/portlib/NdbDir.cpp	2010-09-23 09:02:47 +0000
@@ -199,11 +199,15 @@ mode_t NdbDir::o_x(void) { return IF_WIN
 
 
 bool
-NdbDir::create(const char *dir, mode_t mode)
+NdbDir::create(const char *dir, mode_t mode, bool ignore_existing)
 {
 #ifdef _WIN32
   if (CreateDirectory(dir, NULL) == 0)
   {
+    if (ignore_existing &&
+        GetLastError() == ERROR_ALREADY_EXISTS)
+      return true;
+
     fprintf(stderr,
             "Failed to create directory '%s', error: %d",
             dir, GetLastError());
@@ -212,6 +216,9 @@ NdbDir::create(const char *dir, mode_t m
 #else
   if (mkdir(dir, mode) != 0)
   {
+    if (ignore_existing && errno == EEXIST)
+      return true;
+
     fprintf(stderr,
             "Failed to create directory '%s', error: %d",
             dir, errno);
@@ -464,6 +471,14 @@ TAPTEST(DirIterator)
   CHECK(NdbDir::remove_recursive(path));
   CHECK(gone(path));
 
+  // Create already existing directory
+  CHECK(NdbDir::create(path, NdbDir::u_rwx()));
+  CHECK(!gone(path));
+  CHECK(NdbDir::create(path, NdbDir::u_rwx(), true /* ignore existing!! */));
+  CHECK(!gone(path));
+  CHECK(NdbDir::remove_recursive(path));
+  CHECK(gone(path));
+
   printf("Testing NdbDir::chdir...\n");
   // Try chdir to the non existing dir, should fail
   CHECK(NdbDir::chdir(path) != 0);

=== modified file 'storage/ndb/test/run-test/files.cpp'
--- a/storage/ndb/test/run-test/files.cpp	2010-08-23 08:46:34 +0000
+++ b/storage/ndb/test/run-test/files.cpp	2010-09-23 09:02:47 +0000
@@ -350,7 +350,8 @@ create_directory(const char * path)
     cwd.append(list[i].c_str());
     cwd.append("/");
     NdbDir::create(cwd.c_str(),
-                   NdbDir::u_rwx() | NdbDir::g_r() | NdbDir::g_x());
+                   NdbDir::u_rwx() | NdbDir::g_r() | NdbDir::g_x(),
+                   true);
   }
 
   struct stat sbuf;

Attachment: [text/bzr-bundle] bzr/magnus.blaudd@sun.com-20100923090247-3hnhrbpg0nsn5lj4.bundle
Thread
bzr commit into mysql-5.1-telco-7.0 branch (magnus.blaudd:3786) Magnus Blåudd23 Sep