[llvm-commits] CVS: llvm/lib/System/Unix/Path.inc

Chris Lattner lattner at cs.uiuc.edu
Fri Jul 28 15:30:07 PDT 2006



Changes in directory llvm/lib/System/Unix:

Path.inc updated: 1.46 -> 1.47
---
Log message:

Modify Path::eraseFromDisk to not throw an exception.


---
Diffs of the changes:  (+29 -24)

 Path.inc |   53 +++++++++++++++++++++++++++++------------------------
 1 files changed, 29 insertions(+), 24 deletions(-)


Index: llvm/lib/System/Unix/Path.inc
diff -u llvm/lib/System/Unix/Path.inc:1.46 llvm/lib/System/Unix/Path.inc:1.47
--- llvm/lib/System/Unix/Path.inc:1.46	Fri Jul 28 17:03:44 2006
+++ llvm/lib/System/Unix/Path.inc	Fri Jul 28 17:29:50 2006
@@ -604,33 +604,38 @@
 }
 
 bool
-Path::eraseFromDisk(bool remove_contents) const {
-  // Make sure we're dealing with a directory
+Path::eraseFromDisk(bool remove_contents, std::string *ErrStr) const {
+  // Make sure we're dealing with a directory.
   if (isFile()) {
-    if (0 != unlink(path.c_str()))
-      ThrowErrno(path + ": can't destroy file");
-  } else if (isDirectory()) {
-    if (remove_contents) {
-      // Recursively descend the directory to remove its content
-      std::string cmd("/bin/rm -rf ");
-      cmd += path;
-      system(cmd.c_str());
-    } else {
-      // Otherwise, try to just remove the one directory
-      char pathname[MAXPATHLEN];
-      path.copy(pathname,MAXPATHLEN);
-      int lastchar = path.length() - 1 ; 
-      if (pathname[lastchar] == '/') 
-        pathname[lastchar] = 0;
-      else
-        pathname[lastchar+1] = 0;
-      if ( 0 != rmdir(pathname))
-        ThrowErrno(std::string(pathname) + ": can't destroy directory");
-    }
+    if (unlink(path.c_str()) != 0)
+      return GetErrno(path + ": can't destroy file", ErrStr);
+    return false;
   }
-  else
+  
+  if (!isDirectory()) {
+    if (ErrStr) *ErrStr = "not a file or directory";
+    return true;
+  }
+  if (remove_contents) {
+    // Recursively descend the directory to remove its contents.
+    std::string cmd = "/bin/rm -rf " + path;
+    system(cmd.c_str());
     return false;
-  return true;
+  }
+
+  // Otherwise, try to just remove the one directory.
+  char pathname[MAXPATHLEN];
+  path.copy(pathname, MAXPATHLEN);
+  int lastchar = path.length() - 1 ; 
+  if (pathname[lastchar] == '/') 
+    pathname[lastchar] = 0;
+  else
+    pathname[lastchar+1] = 0;
+    
+  if (rmdir(pathname) != 0)
+    return GetErrno(std::string(pathname) + ": can't destroy directory",
+                    ErrStr);
+  return false;
 }
 
 bool






More information about the llvm-commits mailing list