mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-01-05 12:31:33 +00:00
Remove remove_all. A compiler has no need for recursively deleting a directory.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@198955 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
d91c160b0a
commit
217c714a67
@ -341,22 +341,6 @@ inline error_code remove(const Twine &Path) {
|
|||||||
return remove(Path, Existed);
|
return remove(Path, Existed);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @brief Recursively remove all files below \a path, then \a path. Files are
|
|
||||||
/// removed as if by POSIX remove().
|
|
||||||
///
|
|
||||||
/// @param path Input path.
|
|
||||||
/// @param num_removed Number of files removed.
|
|
||||||
/// @returns errc::success if path has been removed and num_removed has been
|
|
||||||
/// successfully set, otherwise a platform specific error_code.
|
|
||||||
error_code remove_all(const Twine &path, uint32_t &num_removed);
|
|
||||||
|
|
||||||
/// @brief Convenience function for clients that don't need to know how many
|
|
||||||
/// files were removed.
|
|
||||||
inline error_code remove_all(const Twine &Path) {
|
|
||||||
uint32_t Removed;
|
|
||||||
return remove_all(Path, Removed);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @brief Rename \a from to \a to. Files are renamed as if by POSIX rename().
|
/// @brief Rename \a from to \a to. Files are renamed as if by POSIX rename().
|
||||||
///
|
///
|
||||||
/// @param from The path to rename from.
|
/// @param from The path to rename from.
|
||||||
|
@ -983,45 +983,6 @@ error_code identify_magic(const Twine &path, file_magic &result) {
|
|||||||
return error_code::success();
|
return error_code::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;
|
|
||||||
directory_iterator i(path, ec);
|
|
||||||
if (ec) return ec;
|
|
||||||
for (directory_iterator 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 error_code::success();
|
|
||||||
}
|
|
||||||
} // end unnamed namespace
|
|
||||||
|
|
||||||
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 {
|
error_code directory_entry::status(file_status &result) const {
|
||||||
return fs::status(Path, result);
|
return fs::status(Path, result);
|
||||||
}
|
}
|
||||||
|
@ -56,6 +56,7 @@ TEST(FileOutputBuffer, Test) {
|
|||||||
uint64_t File1Size;
|
uint64_t File1Size;
|
||||||
ASSERT_NO_ERROR(fs::file_size(Twine(File1), File1Size));
|
ASSERT_NO_ERROR(fs::file_size(Twine(File1), File1Size));
|
||||||
ASSERT_EQ(File1Size, 8192ULL);
|
ASSERT_EQ(File1Size, 8192ULL);
|
||||||
|
ASSERT_NO_ERROR(fs::remove(File1.str()));
|
||||||
|
|
||||||
// TEST 2: Verify abort case.
|
// TEST 2: Verify abort case.
|
||||||
SmallString<128> File2(TestDirectory);
|
SmallString<128> File2(TestDirectory);
|
||||||
@ -71,6 +72,7 @@ TEST(FileOutputBuffer, Test) {
|
|||||||
bool Exists = false;
|
bool Exists = false;
|
||||||
ASSERT_NO_ERROR(fs::exists(Twine(File2), Exists));
|
ASSERT_NO_ERROR(fs::exists(Twine(File2), Exists));
|
||||||
EXPECT_FALSE(Exists);
|
EXPECT_FALSE(Exists);
|
||||||
|
ASSERT_NO_ERROR(fs::remove(File2.str()));
|
||||||
|
|
||||||
// TEST 3: Verify sizing down case.
|
// TEST 3: Verify sizing down case.
|
||||||
SmallString<128> File3(TestDirectory);
|
SmallString<128> File3(TestDirectory);
|
||||||
@ -94,6 +96,7 @@ TEST(FileOutputBuffer, Test) {
|
|||||||
uint64_t File3Size;
|
uint64_t File3Size;
|
||||||
ASSERT_NO_ERROR(fs::file_size(Twine(File3), File3Size));
|
ASSERT_NO_ERROR(fs::file_size(Twine(File3), File3Size));
|
||||||
ASSERT_EQ(File3Size, 5000ULL);
|
ASSERT_EQ(File3Size, 5000ULL);
|
||||||
|
ASSERT_NO_ERROR(fs::remove(File3.str()));
|
||||||
|
|
||||||
// TEST 4: Verify file can be made executable.
|
// TEST 4: Verify file can be made executable.
|
||||||
SmallString<128> File4(TestDirectory);
|
SmallString<128> File4(TestDirectory);
|
||||||
@ -112,9 +115,9 @@ TEST(FileOutputBuffer, Test) {
|
|||||||
ASSERT_NO_ERROR(fs::status(Twine(File4), Status));
|
ASSERT_NO_ERROR(fs::status(Twine(File4), Status));
|
||||||
bool IsExecutable = (Status.permissions() & fs::owner_exe);
|
bool IsExecutable = (Status.permissions() & fs::owner_exe);
|
||||||
EXPECT_TRUE(IsExecutable);
|
EXPECT_TRUE(IsExecutable);
|
||||||
|
ASSERT_NO_ERROR(fs::remove(File4.str()));
|
||||||
|
|
||||||
// Clean up.
|
// Clean up.
|
||||||
uint32_t RemovedCount;
|
ASSERT_NO_ERROR(fs::remove(TestDirectory.str()));
|
||||||
ASSERT_NO_ERROR(fs::remove_all(TestDirectory.str(), RemovedCount));
|
|
||||||
}
|
}
|
||||||
} // anonymous namespace
|
} // anonymous namespace
|
||||||
|
@ -40,7 +40,8 @@ TEST(LockFileManagerTest, Basic) {
|
|||||||
// Now that the lock is out of scope, the file should be gone.
|
// Now that the lock is out of scope, the file should be gone.
|
||||||
EXPECT_FALSE(sys::fs::exists(StringRef(LockedFile)));
|
EXPECT_FALSE(sys::fs::exists(StringRef(LockedFile)));
|
||||||
|
|
||||||
sys::fs::remove_all(StringRef(TmpDir));
|
EC = sys::fs::remove(StringRef(TmpDir));
|
||||||
|
ASSERT_FALSE(EC);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // end anonymous namespace
|
} // end anonymous namespace
|
||||||
|
@ -225,8 +225,7 @@ protected:
|
|||||||
}
|
}
|
||||||
|
|
||||||
virtual void TearDown() {
|
virtual void TearDown() {
|
||||||
uint32_t removed;
|
ASSERT_NO_ERROR(fs::remove(TestDirectory.str()));
|
||||||
ASSERT_NO_ERROR(fs::remove_all(TestDirectory.str(), removed));
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -414,6 +413,18 @@ TEST_F(FileSystemTest, DirectoryIteration) {
|
|||||||
ASSERT_LT(a0, aa1);
|
ASSERT_LT(a0, aa1);
|
||||||
ASSERT_LT(a0, ab1);
|
ASSERT_LT(a0, ab1);
|
||||||
ASSERT_LT(z0, za1);
|
ASSERT_LT(z0, za1);
|
||||||
|
|
||||||
|
ASSERT_NO_ERROR(fs::remove(Twine(TestDirectory) + "/recursive/a0/aa1"));
|
||||||
|
ASSERT_NO_ERROR(fs::remove(Twine(TestDirectory) + "/recursive/a0/ab1"));
|
||||||
|
ASSERT_NO_ERROR(fs::remove(Twine(TestDirectory) + "/recursive/a0"));
|
||||||
|
ASSERT_NO_ERROR(
|
||||||
|
fs::remove(Twine(TestDirectory) + "/recursive/dontlookhere/da1"));
|
||||||
|
ASSERT_NO_ERROR(fs::remove(Twine(TestDirectory) + "/recursive/dontlookhere"));
|
||||||
|
ASSERT_NO_ERROR(fs::remove(Twine(TestDirectory) + "/recursive/pop/p1"));
|
||||||
|
ASSERT_NO_ERROR(fs::remove(Twine(TestDirectory) + "/recursive/pop"));
|
||||||
|
ASSERT_NO_ERROR(fs::remove(Twine(TestDirectory) + "/recursive/z0/za1"));
|
||||||
|
ASSERT_NO_ERROR(fs::remove(Twine(TestDirectory) + "/recursive/z0"));
|
||||||
|
ASSERT_NO_ERROR(fs::remove(Twine(TestDirectory) + "/recursive"));
|
||||||
}
|
}
|
||||||
|
|
||||||
const char archive[] = "!<arch>\x0A";
|
const char archive[] = "!<arch>\x0A";
|
||||||
@ -479,6 +490,7 @@ TEST_F(FileSystemTest, Magic) {
|
|||||||
ASSERT_NO_ERROR(fs::has_magic(file_pathname.c_str(), magic, res));
|
ASSERT_NO_ERROR(fs::has_magic(file_pathname.c_str(), magic, res));
|
||||||
EXPECT_TRUE(res);
|
EXPECT_TRUE(res);
|
||||||
EXPECT_EQ(i->magic, fs::identify_magic(magic));
|
EXPECT_EQ(i->magic, fs::identify_magic(magic));
|
||||||
|
ASSERT_NO_ERROR(fs::remove(Twine(file_pathname)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -509,6 +521,7 @@ TEST_F(FileSystemTest, CarriageReturn) {
|
|||||||
MemoryBuffer::getFile(FilePathname.c_str(), Buf);
|
MemoryBuffer::getFile(FilePathname.c_str(), Buf);
|
||||||
EXPECT_EQ(Buf->getBuffer(), "\n");
|
EXPECT_EQ(Buf->getBuffer(), "\n");
|
||||||
}
|
}
|
||||||
|
ASSERT_NO_ERROR(fs::remove(Twine(FilePathname)));
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user