[llvm] r187463 - Fix windows' implementation of status when a file doesn't exist.

Rafael Espindola rafael.espindola at gmail.com
Tue Jul 30 17:10:25 PDT 2013


Author: rafael
Date: Tue Jul 30 19:10:25 2013
New Revision: 187463

URL: http://llvm.org/viewvc/llvm-project?rev=187463&view=rev
Log:
Fix windows' implementation of status when a file doesn't exist.

The unix one was returning no_such_file_or_directory, but the windows one
was return success.

Update the one one caller that was depending on the old behavior.

Modified:
    llvm/trunk/lib/Support/Windows/Path.inc
    llvm/trunk/unittests/Support/Path.cpp

Modified: llvm/trunk/lib/Support/Windows/Path.inc
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Windows/Path.inc?rev=187463&r1=187462&r2=187463&view=diff
==============================================================================
--- llvm/trunk/lib/Support/Windows/Path.inc (original)
+++ llvm/trunk/lib/Support/Windows/Path.inc Tue Jul 30 19:10:25 2013
@@ -399,8 +399,15 @@ error_code remove(const Twine &path, boo
   SmallVector<wchar_t, 128> path_utf16;
 
   file_status st;
-  if (error_code ec = status(path, st))
-    return ec;
+  error_code EC = status(path, st);
+  if (EC) {
+    if (EC == windows_error::file_not_found ||
+        EC == windows_error::path_not_found) {
+      existed = false;
+      return error_code::success();
+    }
+    return EC;
+  }
 
   if (error_code ec = UTF8ToUTF16(path.toStringRef(path_storage),
                                   path_utf16))
@@ -611,11 +618,9 @@ handle_status_error:
     Result = file_status(file_type::file_not_found);
   else if (EC == windows_error::sharing_violation)
     Result = file_status(file_type::type_unknown);
-  else {
+  else
     Result = file_status(file_type::status_error);
-    return EC;
-  }
-  return error_code::success();
+  return EC;
 }
 
 error_code status(const Twine &path, file_status &result) {

Modified: llvm/trunk/unittests/Support/Path.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Support/Path.cpp?rev=187463&r1=187462&r2=187463&view=diff
==============================================================================
--- llvm/trunk/unittests/Support/Path.cpp (original)
+++ llvm/trunk/unittests/Support/Path.cpp Tue Jul 30 19:10:25 2013
@@ -240,6 +240,10 @@ TEST_F(FileSystemTest, TempFiles) {
   ASSERT_NO_ERROR(fs::remove(Twine(TempPath2), TempFileExists));
   EXPECT_TRUE(TempFileExists);
 
+  error_code EC = fs::status(TempPath2.c_str(), B);
+  EXPECT_EQ(EC, errc::no_such_file_or_directory);
+  EXPECT_EQ(B.type(), fs::file_type::file_not_found);
+
   // Make sure Temp2 doesn't exist.
   ASSERT_NO_ERROR(fs::exists(Twine(TempPath2), TempFileExists));
   EXPECT_FALSE(TempFileExists);





More information about the llvm-commits mailing list