summaryrefslogtreecommitdiff
path: root/lib/Support/PathV2.cpp
diff options
context:
space:
mode:
authorMichael J. Spencer <bigcheesegs@gmail.com>2011-01-05 16:39:38 +0000
committerMichael J. Spencer <bigcheesegs@gmail.com>2011-01-05 16:39:38 +0000
commit7fd682aaf2ceeb953da190a2add326963ff45c3e (patch)
tree7fab26c0e0d8d166e58bee5d9a011d14cdc19fbd /lib/Support/PathV2.cpp
parent277fa1047bbf66dc998e20cd2c8a666ce414f6ab (diff)
downloadllvm-7fd682aaf2ceeb953da190a2add326963ff45c3e.tar.gz
llvm-7fd682aaf2ceeb953da190a2add326963ff45c3e.tar.bz2
llvm-7fd682aaf2ceeb953da190a2add326963ff45c3e.tar.xz
Support/PathV2: Implement remove_all.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@122884 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Support/PathV2.cpp')
-rw-r--r--lib/Support/PathV2.cpp37
1 files changed, 37 insertions, 0 deletions
diff --git a/lib/Support/PathV2.cpp b/lib/Support/PathV2.cpp
index 481a038778..3b232abf7d 100644
--- a/lib/Support/PathV2.cpp
+++ b/lib/Support/PathV2.cpp
@@ -697,6 +697,43 @@ error_code has_magic(const Twine &path, const Twine &magic, bool &result) {
return success;
}
+namespace {
+error_code remove_all_r(StringRef path, file_type ft, uint32_t &count) {
+ if (ft == file_type::directory_file) {
+ // This code would be a lot better with exceptions ;/.
+ error_code ec;
+ for (directory_iterator i(path, ec), e; i != e; i.increment(ec)) {
+ if (ec) return ec;
+ file_status st;
+ if (error_code ec = i->status(st)) return ec;
+ if (error_code ec = remove_all_r(i->path(), st.type(), count)) return ec;
+ }
+ bool obviously_this_exists;
+ if (error_code ec = remove(path, obviously_this_exists)) return ec;
+ assert(obviously_this_exists);
+ ++count; // Include the directory itself in the items removed.
+ } else {
+ bool obviously_this_exists;
+ if (error_code ec = remove(path, obviously_this_exists)) return ec;
+ assert(obviously_this_exists);
+ ++count;
+ }
+
+ return success;
+}
+}
+
+error_code remove_all(const Twine &path, uint32_t &num_removed) {
+ SmallString<128> path_storage;
+ StringRef p = path.toStringRef(path_storage);
+
+ file_status fs;
+ if (error_code ec = status(path, fs))
+ return ec;
+ num_removed = 0;
+ return remove_all_r(p, fs.type(), num_removed);
+}
+
error_code directory_entry::status(file_status &result) const {
return fs::status(Path, result);
}