Modify Path::eraseFromDisk to not throw an exception.
[oota-llvm.git] / lib / System / Win32 / Path.inc
index 27baf827566054e93731178d8d42b3d52e3fa7a9..15c686d2640d5c2643e9d9ef4beadcd5416ab14b 100644 (file)
@@ -121,7 +121,7 @@ Path::GetTemporaryDirectory() {
 
   // Append a subdirectory passed on our process id so multiple LLVMs don't
   // step on each other's toes.
-  sprintf(pathname, "LLVM_%u", GetCurrentProcessId());
+  sprintf(pathname, "LLVM_%u", unsigned(GetCurrentProcessId()));
   result.appendComponent(pathname);
 
   // If there's a directory left over from a previous LLVM execution that
@@ -222,8 +222,9 @@ Path::isFile() const {
   BOOL rc = GetFileAttributesEx(path.c_str(), GetFileExInfoStandard, &fi);
   if (rc)
     return !(fi.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY);
-  else if (GetLastError() != ERROR_NOT_FOUND)
-    ThrowError(std::string(path) + ": Can't get status: ");
+  else if (GetLastError() != ERROR_FILE_NOT_FOUND) {
+    ThrowError("isFile(): " + std::string(path) + ": Can't get status: ");
+  }
   return false;
 }
 
@@ -233,8 +234,8 @@ Path::isDirectory() const {
   BOOL rc = GetFileAttributesEx(path.c_str(), GetFileExInfoStandard, &fi);
   if (rc)
     return fi.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY;
-  else if (GetLastError() != ERROR_NOT_FOUND)
-    ThrowError(std::string(path) + ": Can't get status: ");
+  else if (GetLastError() != ERROR_FILE_NOT_FOUND)
+    ThrowError("isDirectory(): " + std::string(path) + ": Can't get status: ");
   return false;
 }
 
@@ -244,8 +245,8 @@ Path::isHidden() const {
   BOOL rc = GetFileAttributesEx(path.c_str(), GetFileExInfoStandard, &fi);
   if (rc)
     return fi.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN;
-  else if (GetLastError() != ERROR_NOT_FOUND)
-    ThrowError(std::string(path) + ": Can't get status: ");
+  else if (GetLastError() != ERROR_FILE_NOT_FOUND)
+    ThrowError("isHidden(): " + std::string(path) + ": Can't get status: ");
   return false;
 }
 
@@ -336,10 +337,10 @@ void
 Path::getStatusInfo(StatusInfo& info) const {
   WIN32_FILE_ATTRIBUTE_DATA fi;
   if (!GetFileAttributesEx(path.c_str(), GetFileExInfoStandard, &fi))
-    ThrowError(std::string(path) + ": Can't get status: ");
+    ThrowError("getStatusInfo():" + std::string(path) + ": Can't get status: ");
 
   info.fileSize = fi.nFileSizeHigh;
-  info.fileSize <<= 32;
+  info.fileSize <<= sizeof(fi.nFileSizeHigh)*8;
   info.fileSize += fi.nFileSizeLow;
 
   info.mode = fi.dwFileAttributes & FILE_ATTRIBUTE_READONLY ? 0555 : 0777;
@@ -570,19 +571,19 @@ Path::createFileOnDisk() {
 }
 
 bool
-Path::eraseFromDisk(bool remove_contents) const {
+Path::eraseFromDisk(bool remove_contents, std::string *ErrStr) const {
   if (isFile()) {
     DWORD attr = GetFileAttributes(path.c_str());
 
     // If it doesn't exist, we're done.
     if (attr == INVALID_FILE_ATTRIBUTES)
-      return true;
+      return false;
 
     // Read-only files cannot be deleted on Windows.  Must remove the read-only
     // attribute first.
     if (attr & FILE_ATTRIBUTE_READONLY) {
       if (!SetFileAttributes(path.c_str(), attr & ~FILE_ATTRIBUTE_READONLY))
-        ThrowError(path + ": Can't destroy file: ");
+        return GetError(path + ": Can't destroy file: ", ErrStr);
     }
 
     if (!DeleteFile(path.c_str()))
@@ -591,7 +592,7 @@ Path::eraseFromDisk(bool remove_contents) const {
   } else if (isDirectory()) {
     // If it doesn't exist, we're done.
     if (!exists())
-      return true;
+      return false;
 
     char *pathname = reinterpret_cast<char *>(_alloca(path.length()+3));
     int lastchar = path.length() - 1 ;
@@ -628,7 +629,7 @@ Path::eraseFromDisk(bool remove_contents) const {
         FindClose(h);
         if (err != ERROR_NO_MORE_FILES) {
           SetLastError(err);
-          ThrowError(path + ": Can't read directory: ");
+          return GetError(path + ": Can't read directory: ", ErrStr);
         }
 
         for (std::vector<Path>::iterator I = list.begin(); I != list.end();
@@ -638,17 +639,18 @@ Path::eraseFromDisk(bool remove_contents) const {
         }
       } else {
         if (GetLastError() != ERROR_FILE_NOT_FOUND)
-          ThrowError(path + ": Can't read directory: ");
+          return GetError(path + ": Can't read directory: ", ErrStr);
       }
     }
 
     pathname[lastchar] = 0;
     if (!RemoveDirectory(pathname))
-      ThrowError(std::string(pathname) + ": Can't destroy directory: ");
-    return true;
+      return GetError(std::string(pathname) + ": Can't destroy directory: ",
+                      ErrStr);
+    return false;
   } else {
     // It appears the path doesn't exist.
-    return false;
+    return true;
   }
 }
 
@@ -788,5 +790,3 @@ Path::createTemporaryFileOnDisk(bool reuse_current) {
 
 }
 }
-
-