[llvm-commits] [llvm] r122882 - /llvm/trunk/lib/Support/Windows/PathV2.inc

Michael J. Spencer bigcheesegs at gmail.com
Wed Jan 5 08:39:22 PST 2011


Author: mspencer
Date: Wed Jan  5 10:39:22 2011
New Revision: 122882

URL: http://llvm.org/viewvc/llvm-project?rev=122882&view=rev
Log:
Support/Windows/PathV2: Fix remove to handle both files and directories.

Modified:
    llvm/trunk/lib/Support/Windows/PathV2.inc

Modified: llvm/trunk/lib/Support/Windows/PathV2.inc
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Windows/PathV2.inc?rev=122882&r1=122881&r2=122882&view=diff
==============================================================================
--- llvm/trunk/lib/Support/Windows/PathV2.inc (original)
+++ llvm/trunk/lib/Support/Windows/PathV2.inc Wed Jan  5 10:39:22 2011
@@ -268,17 +268,31 @@
   SmallString<128> path_storage;
   SmallVector<wchar_t, 128> path_utf16;
 
+  file_status st;
+  if (error_code ec = status(path, st))
+    return ec;
+
   if (error_code ec = UTF8ToUTF16(path.toStringRef(path_storage),
                                   path_utf16))
     return ec;
 
-  if (!::DeleteFileW(path_utf16.begin())) {
-    error_code ec = windows_error(::GetLastError());
-    if (ec != windows_error::file_not_found)
-      return ec;
-    existed = false;
-  } else
-    existed = true;
+  if (st.type() == file_type::directory_file) {
+    if (!::RemoveDirectoryW(c_str(path_utf16))) {
+      error_code ec = windows_error(::GetLastError());
+      if (ec != windows_error::file_not_found)
+        return ec;
+      existed = false;
+    } else
+      existed = true;
+  } else {
+    if (!::DeleteFileW(c_str(path_utf16))) {
+      error_code ec = windows_error(::GetLastError());
+      if (ec != windows_error::file_not_found)
+        return ec;
+      existed = false;
+    } else
+      existed = true;
+  }
 
   return success;
 }





More information about the llvm-commits mailing list