diff options
author | Chris Lattner <sabre@nondot.org> | 2006-07-28 22:29:50 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2006-07-28 22:29:50 +0000 |
commit | 3cec10996725038a9cdb483ebd2f57a9dc054509 (patch) | |
tree | da139d1205b695adc8eb2ff6dc3f02b6113b6ed5 /llvm/lib/System/Unix/Path.inc | |
parent | 2091cc86af1a468c3fadc17d41f2e072d431214a (diff) | |
download | bcm5719-llvm-3cec10996725038a9cdb483ebd2f57a9dc054509.tar.gz bcm5719-llvm-3cec10996725038a9cdb483ebd2f57a9dc054509.zip |
Modify Path::eraseFromDisk to not throw an exception.
llvm-svn: 29400
Diffstat (limited to 'llvm/lib/System/Unix/Path.inc')
-rw-r--r-- | llvm/lib/System/Unix/Path.inc | 53 |
1 files changed, 29 insertions, 24 deletions
diff --git a/llvm/lib/System/Unix/Path.inc b/llvm/lib/System/Unix/Path.inc index a0d76b032b4..26f29c0bc0c 100644 --- a/llvm/lib/System/Unix/Path.inc +++ b/llvm/lib/System/Unix/Path.inc @@ -604,33 +604,38 @@ Path::createTemporaryFileOnDisk(bool reuse_current) { } 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 |