diff options
| author | Nicole Mazzuca <mazzucan@outlook.com> | 2019-08-02 16:49:45 -0700 |
|---|---|---|
| committer | nicole mazzuca <mazzucan@outlook.com> | 2019-08-07 16:51:12 -0700 |
| commit | e79f0dc5328f28b2b3942e2cd0e9b0c1accca4a1 (patch) | |
| tree | 2324fcb9eadec792148e02f984525dacb8297883 /toolsrc/src/vcpkg-test/util.cpp | |
| parent | 65cb5cd00cba333e3a41433058e42a114f61fb78 (diff) | |
| download | vcpkg-e79f0dc5328f28b2b3942e2cd0e9b0c1accca4a1.tar.gz vcpkg-e79f0dc5328f28b2b3942e2cd0e9b0c1accca4a1.zip | |
[vcpkg] Make Filesystem::remove_all faster #7570
I added benchmarks to measure how fast the parallel remove_all code was
-- it turns out, about 3x slower than stdfs::remove_all. Since this was
the case, I removed all of the parallelism and rewrote it serially, and
ended up about 30% faster than stdfs::remove_all (in addition to
supporting symlinks).
In addition, I did the following three orthogonal changes:
- simplified the work queue, basing it on Billy O'Neal's idea
- Fix warnings on older versions of compilers in tests, by splitting
the pragmas out of pch.h.
- Ran clang-format on some files
In fixing up remove_all, the following changes were made:
- On Windows, regular symlinks and directory symlinks are distinct;
as an example, to remove directory symlinks (and junctions, for that
matter), one must use RemoveDirectory. Only on Windows, I added new
`file_type` and `file_status` types, with `file_type` including a new
`directory_symlink` enumerator, and `file_status` being exactly the
same as the old one except using the new `file_type`. On Unix, I
didn't make that change since they don't make a distinction.
- I added new `symlink_status` and `status` functions which use the
new `file_status` on Windows.
- I made `Filesystem::exists` call `fs::exists(status(p))`, as opposed
to the old version which called `stdfs::exists` directly.
- Added benchmarks to `vcpkg-test/files.cpp`. They test the
performance of `remove_all` on small directories (~20 files), with
symlinks and without, and on large directories (~2000 files), with
symlinks and without.
Diffstat (limited to 'toolsrc/src/vcpkg-test/util.cpp')
| -rw-r--r-- | toolsrc/src/vcpkg-test/util.cpp | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/toolsrc/src/vcpkg-test/util.cpp b/toolsrc/src/vcpkg-test/util.cpp index 5359b0fad..384954b4e 100644 --- a/toolsrc/src/vcpkg-test/util.cpp +++ b/toolsrc/src/vcpkg-test/util.cpp @@ -74,14 +74,14 @@ namespace vcpkg::Test return m_ret.value_or_exit(VCPKG_LINE_INFO); } - static bool system_allows_symlinks() + static AllowSymlinks internal_can_create_symlinks() noexcept { #if FILESYSTEM_SYMLINK == FILESYSTEM_SYMLINK_NONE - return false; + return AllowSymlinks::No; #elif FILESYSTEM_SYMLINK == FILESYSTEM_SYMLINK_UNIX - return true; + return AllowSymlinks::Yes; #elif !defined(_WIN32) // FILESYSTEM_SYMLINK == FILESYSTEM_SYMLINK_STD - return true; + return AllowSymlinks::Yes; #else HKEY key; bool allow_symlinks = true; @@ -97,11 +97,14 @@ namespace vcpkg::Test if (status == ERROR_SUCCESS) RegCloseKey(key); - return allow_symlinks; + return allow_symlinks ? AllowSymlinks::Yes : AllowSymlinks::No; #endif } + const static AllowSymlinks CAN_CREATE_SYMLINKS = internal_can_create_symlinks(); - static fs::path internal_temporary_directory() + AllowSymlinks can_create_symlinks() noexcept { return CAN_CREATE_SYMLINKS; } + + static fs::path internal_base_temporary_directory() { #if defined(_WIN32) wchar_t* tmp = static_cast<wchar_t*>(std::calloc(32'767, 2)); @@ -121,8 +124,9 @@ namespace vcpkg::Test #endif } - const bool SYMLINKS_ALLOWED = system_allows_symlinks(); - const fs::path TEMPORARY_DIRECTORY = internal_temporary_directory(); + const static fs::path BASE_TEMPORARY_DIRECTORY = internal_base_temporary_directory(); + + const fs::path& base_temporary_directory() noexcept { return BASE_TEMPORARY_DIRECTORY; } #if FILESYSTEM_SYMLINK == FILESYSTEM_SYMLINK_NONE constexpr char no_filesystem_message[] = @@ -132,7 +136,7 @@ namespace vcpkg::Test void create_symlink(const fs::path& target, const fs::path& file, std::error_code& ec) { #if FILESYSTEM_SYMLINK == FILESYSTEM_SYMLINK_STD - if (SYMLINKS_ALLOWED) + if (can_create_symlinks()) { std::filesystem::path targetp = target.native(); std::filesystem::path filep = file.native(); @@ -156,12 +160,12 @@ namespace vcpkg::Test void create_directory_symlink(const fs::path& target, const fs::path& file, std::error_code& ec) { #if FILESYSTEM_SYMLINK == FILESYSTEM_SYMLINK_STD - if (SYMLINKS_ALLOWED) + if (can_create_symlinks()) { std::filesystem::path targetp = target.native(); std::filesystem::path filep = file.native(); - std::filesystem::create_symlink(targetp, filep); + std::filesystem::create_directory_symlink(targetp, filep); } else { |
