diff options
| author | Robert Schumacher <roschuma@microsoft.com> | 2020-03-25 15:18:10 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-03-25 15:18:10 -0700 |
| commit | 42ad12f91d62a6533d909d8b5ee3a46009c2a10a (patch) | |
| tree | db0d7d7e445546afceac0d38fe9cfaf219dff93c /toolsrc/src | |
| parent | 52273558f64dda28bb3c5ada3ee2c33564a5fd31 (diff) | |
| download | vcpkg-42ad12f91d62a6533d909d8b5ee3a46009c2a10a.tar.gz vcpkg-42ad12f91d62a6533d909d8b5ee3a46009c2a10a.zip | |
[vcpkg] Improve common case of ignoring filesystem errors (#10557)
Diffstat (limited to 'toolsrc/src')
| -rw-r--r-- | toolsrc/src/vcpkg/base/files.cpp | 55 | ||||
| -rw-r--r-- | toolsrc/src/vcpkg/binarycaching.cpp | 8 |
2 files changed, 53 insertions, 10 deletions
diff --git a/toolsrc/src/vcpkg/base/files.cpp b/toolsrc/src/vcpkg/base/files.cpp index cd8fba129..0bd1cb893 100644 --- a/toolsrc/src/vcpkg/base/files.cpp +++ b/toolsrc/src/vcpkg/base/files.cpp @@ -173,6 +173,12 @@ namespace vcpkg::Files return r; } + bool Filesystem::remove(const fs::path& path, ignore_errors_t) + { + std::error_code ec; + return this->remove(path, ec); + } + bool Filesystem::exists(const fs::path& path, std::error_code& ec) const { return fs::exists(this->symlink_status(path, ec)); @@ -185,12 +191,23 @@ namespace vcpkg::Files if (ec) Checks::exit_with_message(li, "error checking existence of file %s: %s", path.u8string(), ec.message()); return result; } - - bool Filesystem::exists(const fs::path& path) const + + bool Filesystem::exists(const fs::path& path, ignore_errors_t) const + { + std::error_code ec; + return this->exists(path, ec); + } + + bool Filesystem::create_directory(const fs::path& path, ignore_errors_t) + { + std::error_code ec; + return this->create_directory(path, ec); + } + + bool Filesystem::create_directories(const fs::path& path, ignore_errors_t) { std::error_code ec; - // drop this on the floor, for compatibility with existing code - return exists(path, ec); + return this->create_directories(path, ec); } fs::file_status Filesystem::status(vcpkg::LineInfo li, const fs::path& p) const noexcept @@ -202,6 +219,12 @@ namespace vcpkg::Files return result; } + fs::file_status Filesystem::status(const fs::path& p, ignore_errors_t) const noexcept + { + std::error_code ec; + return this->status(p, ec); + } + fs::file_status Filesystem::symlink_status(vcpkg::LineInfo li, const fs::path& p) const noexcept { std::error_code ec; @@ -211,6 +234,12 @@ namespace vcpkg::Files return result; } + fs::file_status Filesystem::symlink_status(const fs::path& p, ignore_errors_t) const noexcept + { + std::error_code ec; + return this->symlink_status(p, ec); + } + void Filesystem::write_lines(const fs::path& path, const std::vector<std::string>& lines, LineInfo linfo) { std::error_code ec; @@ -235,6 +264,14 @@ namespace vcpkg::Files } } + void Filesystem::remove_all(const fs::path& path, ignore_errors_t) + { + std::error_code ec; + fs::path failure_point; + + this->remove_all(path, ec, failure_point); + } + fs::path Filesystem::canonical(LineInfo li, const fs::path& path) const { std::error_code ec; @@ -244,6 +281,11 @@ namespace vcpkg::Files if (ec) Checks::exit_with_message(li, "Error getting canonicalization of %s: %s", path.string(), ec.message()); return result; } + fs::path Filesystem::canonical(const fs::path& path, ignore_errors_t) const + { + std::error_code ec; + return this->canonical(path, ec); + } struct RealFilesystem final : Filesystem { @@ -432,7 +474,8 @@ namespace vcpkg::Files break; } auto remaining = read_bytes; - while (remaining > 0) { + while (remaining > 0) + { auto read_result = write(o_fd, buffer.get(), remaining); if (read_result == -1) { @@ -444,7 +487,7 @@ namespace vcpkg::Files } } - copy_failure: ; + copy_failure:; } #endif if (written_bytes == -1) diff --git a/toolsrc/src/vcpkg/binarycaching.cpp b/toolsrc/src/vcpkg/binarycaching.cpp index af4a879ca..0750366ff 100644 --- a/toolsrc/src/vcpkg/binarycaching.cpp +++ b/toolsrc/src/vcpkg/binarycaching.cpp @@ -123,7 +123,6 @@ namespace const auto& abi_tag = action.package_abi.value_or_exit(VCPKG_LINE_INFO);
auto& spec = action.spec;
auto& fs = paths.get_filesystem();
- std::error_code ec;
const fs::path archives_root_dir = paths.root / "archives";
const std::string archive_name = abi_tag + ".zip";
const fs::path archive_subpath = fs::u8path(abi_tag.substr(0, 2)) / archive_name;
@@ -133,7 +132,8 @@ namespace compress_directory(paths, paths.package_dir(spec), tmp_archive_path);
- fs.create_directories(archive_path.parent_path(), ec);
+ fs.create_directories(archive_path.parent_path(), ignore_errors);
+ std::error_code ec;
fs.rename_or_copy(tmp_archive_path, archive_path, ".tmp", ec);
if (ec)
{
@@ -163,7 +163,7 @@ namespace const auto tmp_log_path = paths.buildtrees / spec.name() / "tmp_failure_logs";
const auto tmp_log_path_destination = tmp_log_path / spec.name();
const auto tmp_failure_zip = paths.buildtrees / spec.name() / "failure_logs.zip";
- fs.create_directories(tmp_log_path_destination, ec);
+ fs.create_directories(tmp_log_path_destination, ignore_errors);
for (auto& log_file : fs::stdfs::directory_iterator(paths.buildtrees / spec.name()))
{
@@ -178,7 +178,7 @@ namespace compress_directory(paths, tmp_log_path, paths.buildtrees / spec.name() / "failure_logs.zip");
- fs.create_directories(archive_tombstone_path.parent_path(), ec);
+ fs.create_directories(archive_tombstone_path.parent_path(), ignore_errors);
fs.rename_or_copy(tmp_failure_zip, archive_tombstone_path, ".tmp", ec);
// clean up temporary directory
|
