Windows: Moved `os::mkdir` to its own file, `stout/os/mkdir`.

review: https://reviews.apache.org/r/39383


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/6e04f6e6
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/6e04f6e6
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/6e04f6e6

Branch: refs/heads/master
Commit: 6e04f6e681413eeaca99b17db3db481a45df13cd
Parents: ffb5105
Author: Alex Clemmer <[email protected]>
Authored: Wed Oct 28 16:01:14 2015 -0500
Committer: Joris Van Remoortere <[email protected]>
Committed: Wed Oct 28 17:11:03 2015 -0500

----------------------------------------------------------------------
 .../3rdparty/stout/include/Makefile.am          |  6 +-
 .../3rdparty/stout/include/stout/os.hpp         | 31 +--------
 .../stout/include/stout/os/constants.hpp        | 25 +++++++
 .../3rdparty/stout/include/stout/os/mkdir.hpp   | 70 ++++++++++++++++++++
 4 files changed, 101 insertions(+), 31 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/6e04f6e6/3rdparty/libprocess/3rdparty/stout/include/Makefile.am
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/Makefile.am 
b/3rdparty/libprocess/3rdparty/stout/include/Makefile.am
index 16db9a6..67b142b 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/Makefile.am
+++ b/3rdparty/libprocess/3rdparty/stout/include/Makefile.am
@@ -55,6 +55,7 @@ nobase_include_HEADERS =              \
   stout/os/bootid.hpp                  \
   stout/os/chdir.hpp                   \
   stout/os/close.hpp                   \
+  stout/os/constants.hpp               \
   stout/os/environment.hpp             \
   stout/os/exists.hpp                  \
   stout/os/fcntl.hpp                   \
@@ -77,11 +78,14 @@ nobase_include_HEADERS =            \
   stout/os/posix/signals.hpp           \
   stout/os/posix/stat.hpp              \
   stout/os/ls.hpp                      \
+  stout/os/mkdir.hpp                   \
   stout/os/mktemp.hpp                  \
   stout/os/open.hpp                    \
   stout/os/os.hpp                      \
   stout/os/osx.hpp                     \
+  stout/os/permissions.hpp             \
   stout/os/process.hpp                 \
+  stout/os/pstree.hpp                  \
   stout/os/read.hpp                    \
   stout/os/realpath.hpp                        \
   stout/os/rename.hpp                  \
@@ -90,8 +94,6 @@ nobase_include_HEADERS =              \
   stout/os/shell.hpp                   \
   stout/os/signals.hpp                 \
   stout/os/stat.hpp                    \
-  stout/os/permissions.hpp             \
-  stout/os/pstree.hpp                  \
   stout/os/sysctl.hpp                  \
   stout/os/touch.hpp                   \
   stout/os/utime.hpp                   \

http://git-wip-us.apache.org/repos/asf/mesos/blob/6e04f6e6/3rdparty/libprocess/3rdparty/stout/include/stout/os.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/os.hpp 
b/3rdparty/libprocess/3rdparty/stout/include/stout/os.hpp
index 05b5845..fc2df68 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/os.hpp
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/os.hpp
@@ -81,9 +81,10 @@
 #include <stout/os/getcwd.hpp>
 #include <stout/os/killtree.hpp>
 #include <stout/os/ls.hpp>
+#include <stout/os/mkdir.hpp>
 #include <stout/os/mktemp.hpp>
-#include <stout/os/permissions.hpp>
 #include <stout/os/os.hpp>
+#include <stout/os/permissions.hpp>
 #include <stout/os/read.hpp>
 #include <stout/os/realpath.hpp>
 #include <stout/os/rename.hpp>
@@ -138,34 +139,6 @@ inline Try<bool> access(const std::string& path, int how)
 }
 
 
-inline Try<Nothing> mkdir(const std::string& directory, bool recursive = true)
-{
-  if (!recursive) {
-    if (::mkdir(directory.c_str(), 0755) < 0) {
-      return ErrnoError();
-    }
-  } else {
-    std::vector<std::string> tokens = strings::tokenize(directory, "/");
-    std::string path = "";
-
-    // We got an absolute path, so keep the leading slash.
-    if (directory.find_first_of("/") == 0) {
-      path = "/";
-    }
-
-    foreach (const std::string& token, tokens) {
-      path += token;
-      if (::mkdir(path.c_str(), 0755) < 0 && errno != EEXIST) {
-        return ErrnoError();
-      }
-      path += "/";
-    }
-  }
-
-  return Nothing();
-}
-
-
 // Return the list of file paths that match the given pattern by recursively
 // searching the given directory. A match is successful if the pattern is a
 // substring of the file name.

http://git-wip-us.apache.org/repos/asf/mesos/blob/6e04f6e6/3rdparty/libprocess/3rdparty/stout/include/stout/os/constants.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/os/constants.hpp 
b/3rdparty/libprocess/3rdparty/stout/include/stout/os/constants.hpp
new file mode 100644
index 0000000..bd8bfb7
--- /dev/null
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/os/constants.hpp
@@ -0,0 +1,25 @@
+/**
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __STOUT_OS_CONSTANTS_HPP__
+#define __STOUT_OS_CONSTANTS_HPP__
+
+#include <string>
+
+namespace os {
+
+const std::string DIRECTORY_SEPARATOR = "/";
+
+} // namespace os {
+
+#endif // __STOUT_OS_CONSTANTS_HPP__

http://git-wip-us.apache.org/repos/asf/mesos/blob/6e04f6e6/3rdparty/libprocess/3rdparty/stout/include/stout/os/mkdir.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/os/mkdir.hpp 
b/3rdparty/libprocess/3rdparty/stout/include/stout/os/mkdir.hpp
new file mode 100644
index 0000000..8c9c0a1
--- /dev/null
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/os/mkdir.hpp
@@ -0,0 +1,70 @@
+/**
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __STOUT_OS_MKDIR_HPP__
+#define __STOUT_OS_MKDIR_HPP__
+
+#ifndef __WINDOWS__
+#include <sys/stat.h>
+#endif // __WINDOWS__
+
+#include <string>
+#include <vector>
+
+#include <stout/error.hpp>
+#include <stout/nothing.hpp>
+#include <stout/strings.hpp>
+#include <stout/try.hpp>
+
+#include <stout/os/constants.hpp>
+
+#ifdef __WINDOWS__
+#include <stout/windows.hpp> // To be certain we're using the right `mkdir`.
+#endif // __WINDOWS__
+
+
+namespace os {
+
+inline Try<Nothing> mkdir(const std::string& directory, bool recursive = true)
+{
+  if (!recursive) {
+    if (::mkdir(directory.c_str(), 0755) < 0) {
+      return ErrnoError();
+    }
+  } else {
+    std::vector<std::string> tokens =
+      strings::tokenize(directory, os::DIRECTORY_SEPARATOR);
+
+    std::string path = "";
+
+    // We got an absolute path, so keep the leading slash.
+    if (directory.find_first_of(os::DIRECTORY_SEPARATOR) == 0) {
+      path = os::DIRECTORY_SEPARATOR;
+    }
+
+    foreach (const std::string& token, tokens) {
+      path += token;
+      if (::mkdir(path.c_str(), 0755) < 0 && errno != EEXIST) {
+        return ErrnoError();
+      }
+
+      path += os::DIRECTORY_SEPARATOR;
+    }
+  }
+
+  return Nothing();
+}
+
+} // namespace os {
+
+#endif // __STOUT_OS_MKDIR_HPP__

Reply via email to