You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by jo...@apache.org on 2017/07/11 01:39:06 UTC

[20/50] mesos git commit: Windows: Updated `os::rmdir()` to support long paths.

Windows: Updated `os::rmdir()` to support long paths.

Review: https://reviews.apache.org/r/60314/


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

Branch: refs/heads/master
Commit: e1abdf9054a9d5ff3f59eb2d0f4c8378ffe5eb85
Parents: f2db53f
Author: Andrew Schwartzmeyer <an...@schwartzmeyer.com>
Authored: Fri Jul 7 16:01:41 2017 -0700
Committer: Joseph Wu <jo...@apache.org>
Committed: Mon Jul 10 17:15:34 2017 -0700

----------------------------------------------------------------------
 .../stout/include/stout/os/windows/rmdir.hpp    | 46 +++++++++++---------
 1 file changed, 26 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/e1abdf90/3rdparty/stout/include/stout/os/windows/rmdir.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/os/windows/rmdir.hpp b/3rdparty/stout/include/stout/os/windows/rmdir.hpp
index 05eceea..76b74f8 100644
--- a/3rdparty/stout/include/stout/os/windows/rmdir.hpp
+++ b/3rdparty/stout/include/stout/os/windows/rmdir.hpp
@@ -26,6 +26,9 @@
 
 #include <stout/windows/error.hpp>
 
+#include <stout/internal/windows/longpath.hpp>
+#include <stout/internal/windows/reparsepoint.hpp>
+
 
 namespace os {
 namespace internal {
@@ -59,27 +62,29 @@ inline Try<Nothing> recursive_remove_directory(
   } else {
     current_path = path;
   }
+  const std::wstring long_current_path =
+      ::internal::windows::longpath(current_path);
 
   // Get first file matching pattern `X:\path\to\wherever\*`.
-  WIN32_FIND_DATA found;
-  const std::string search_pattern = current_path + "*";
+  WIN32_FIND_DATAW found;
+  const std::wstring search_pattern = long_current_path + L"*";
   const SharedHandle search_handle(
-      FindFirstFile(search_pattern.c_str(), &found),
-      FindClose);
+      ::FindFirstFileW(search_pattern.data(), &found),
+      ::FindClose);
 
   if (search_handle.get() == INVALID_HANDLE_VALUE) {
     return WindowsError(
         "`os::internal::recursive_remove_directory` failed when searching "
-        "for files with pattern '" + search_pattern + "'");
+        "for files with pattern '" + stringify(search_pattern) + "'");
   }
 
   do {
     // NOTE: do-while is appropriate here because folder is guaranteed to have
     // at least a file called `.` (and probably also one called `..`).
-    const std::string current_file(found.cFileName);
+    const std::wstring current_file(found.cFileName);
 
-    const bool is_current_directory = current_file.compare(".") == 0;
-    const bool is_parent_directory = current_file.compare("..") == 0;
+    const bool is_current_directory = current_file.compare(L".") == 0;
+    const bool is_parent_directory = current_file.compare(L"..") == 0;
 
     // Don't try to delete `.` and `..` files in directory.
     if (is_current_directory || is_parent_directory) {
@@ -87,7 +92,7 @@ inline Try<Nothing> recursive_remove_directory(
     }
 
     // Path to remove.
-    const std::string current_absolute_path = current_path + current_file;
+    const std::wstring current_absolute_path = long_current_path + current_file;
 
     Try<bool> is_reparse_point =
       ::internal::windows::reparse_point_attribute_set(current_absolute_path);
@@ -102,47 +107,48 @@ inline Try<Nothing> recursive_remove_directory(
       //
       // If either `RemoveDirectory` or `DeleteFile` succeeds, the reparse
       // point has been successfully removed, and we report success.
-      const BOOL rmdir = ::RemoveDirectory(current_absolute_path.c_str());
+      const BOOL rmdir = ::RemoveDirectoryW(current_absolute_path.data());
 
       if (rmdir == FALSE) {
-        const BOOL rm = ::DeleteFile(current_absolute_path.c_str());
+        const BOOL rm = ::DeleteFileW(current_absolute_path.data());
 
         if (rm == FALSE) {
           return WindowsError(
               "Failed to remove reparse point at '" +
-              current_absolute_path + "'");
+              stringify(current_absolute_path) + "'");
         }
       }
-    } else if (os::stat::isdir(current_absolute_path)) {
+    } else if (os::stat::isdir(stringify(current_absolute_path))) {
       Try<Nothing> removed = recursive_remove_directory(
-          current_absolute_path, true, continueOnError);
+          stringify(current_absolute_path), true, continueOnError);
 
       if (removed.isError()) {
         if (continueOnError) {
-          LOG(WARNING) << "Failed to delete directory " << current_absolute_path
+          LOG(WARNING) << "Failed to delete directory "
+                       << stringify(current_absolute_path)
                        << " with error " << removed.error();
         } else {
           return Error(removed.error());
         }
       }
     } else {
-      if (::remove(current_absolute_path.c_str()) != 0) {
+      if (::DeleteFileW(current_absolute_path.data()) == 0) {
         if (continueOnError) {
           LOG(WARNING)
               << "`os::internal::recursive_remove_directory`"
               << " attempted to delete file '"
-              << current_absolute_path << "', but failed";
+              << stringify(current_absolute_path) << "', but failed";
         } else {
           return WindowsError(
               "`os::internal::recursive_remove_directory` attempted to delete "
-              "file '" + current_absolute_path + "', but failed");
+              "file '" + stringify(current_absolute_path) + "', but failed");
         }
       }
     }
-  } while (FindNextFile(search_handle.get(), &found));
+  } while (::FindNextFileW(search_handle.get(), &found));
 
   // Finally, remove current directory unless `removeRoot` is disabled.
-  if (removeRoot && ::_rmdir(current_path.c_str()) == -1) {
+  if (removeRoot && ::RemoveDirectoryW(long_current_path.data()) == FALSE) {
     if (continueOnError) {
       LOG(WARNING) << "`os::internal::recursive_remove_directory`"
                    << " attempted to delete directory '"