summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Support/Unix/Path.inc
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2014-02-23 13:56:14 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2014-02-23 13:56:14 +0000
commit5c20ac0134a0f9eb806f9304ef769c75954efaf7 (patch)
tree3b8217bf1bc3ec86e4059413219d5f1731960fa6 /llvm/lib/Support/Unix/Path.inc
parente842e4b2f1f83efdcc61c0051710cc51bb10c45c (diff)
downloadbcm5719-llvm-5c20ac0134a0f9eb806f9304ef769c75954efaf7.tar.gz
bcm5719-llvm-5c20ac0134a0f9eb806f9304ef769c75954efaf7.zip
Simplify remove, create_directory and create_directories.
Before this patch they would take an boolean argument to say if the path already existed. This was redundant with the returned error_code which is able to represent that. This allowed for callers to incorrectly check only the existed flag instead of first checking the error code. Instead, pass in a boolean flag to say if the previous (non-)existence should be an error or not. Callers of the of the old simple versions are not affected. They still ignore the previous (non-)existence as they did before. llvm-svn: 201979
Diffstat (limited to 'llvm/lib/Support/Unix/Path.inc')
-rw-r--r--llvm/lib/Support/Unix/Path.inc28
1 files changed, 11 insertions, 17 deletions
diff --git a/llvm/lib/Support/Unix/Path.inc b/llvm/lib/Support/Unix/Path.inc
index 20e9642897e..83d2b4284a4 100644
--- a/llvm/lib/Support/Unix/Path.inc
+++ b/llvm/lib/Support/Unix/Path.inc
@@ -164,12 +164,11 @@ retry_random_path:
}
case FS_Dir: {
- bool Existed;
- error_code EC = sys::fs::create_directory(ResultPath.begin(), Existed);
- if (EC)
+ if (error_code EC = sys::fs::create_directory(ResultPath.begin(), false)) {
+ if (EC == errc::file_exists)
+ goto retry_random_path;
return EC;
- if (Existed)
- goto retry_random_path;
+ }
return error_code::success();
}
}
@@ -333,16 +332,14 @@ error_code current_path(SmallVectorImpl<char> &result) {
return error_code::success();
}
-error_code create_directory(const Twine &path, bool &existed) {
+error_code create_directory(const Twine &path, bool IgnoreExisting) {
SmallString<128> path_storage;
StringRef p = path.toNullTerminatedStringRef(path_storage);
if (::mkdir(p.begin(), S_IRWXU | S_IRWXG) == -1) {
- if (errno != errc::file_exists)
+ if (errno != errc::file_exists || !IgnoreExisting)
return error_code(errno, system_category());
- existed = true;
- } else
- existed = false;
+ }
return error_code::success();
}
@@ -360,15 +357,14 @@ error_code create_hard_link(const Twine &to, const Twine &from) {
return error_code::success();
}
-error_code remove(const Twine &path, bool &existed) {
+error_code remove(const Twine &path, bool IgnoreNonExisting) {
SmallString<128> path_storage;
StringRef p = path.toNullTerminatedStringRef(path_storage);
struct stat buf;
if (stat(p.begin(), &buf) != 0) {
- if (errno != errc::no_such_file_or_directory)
+ if (errno != errc::no_such_file_or_directory || !IgnoreNonExisting)
return error_code(errno, system_category());
- existed = false;
return error_code::success();
}
@@ -381,11 +377,9 @@ error_code remove(const Twine &path, bool &existed) {
return make_error_code(errc::operation_not_permitted);
if (::remove(p.begin()) == -1) {
- if (errno != errc::no_such_file_or_directory)
+ if (errno != errc::no_such_file_or_directory || !IgnoreNonExisting)
return error_code(errno, system_category());
- existed = false;
- } else
- existed = true;
+ }
return error_code::success();
}
OpenPOWER on IntegriCloud