Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions toolsrc/include/vcpkg/base/files.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <vcpkg/base/expected.h>
#include <vcpkg/base/ignore_errors.h>

#if USE_STD_FILESYSTEM
#include <filesystem>
Expand Down Expand Up @@ -126,20 +127,22 @@ namespace vcpkg::Files
StringLiteral temp_suffix,
std::error_code& ec) = 0;
bool remove(const fs::path& path, LineInfo linfo);
bool remove(const fs::path& path, ignore_errors_t);
virtual bool remove(const fs::path& path, std::error_code& ec) = 0;

virtual void remove_all(const fs::path& path, std::error_code& ec, fs::path& failure_point) = 0;
void remove_all(const fs::path& path, LineInfo li);
void remove_all(const fs::path& path, ignore_errors_t);
bool exists(const fs::path& path, std::error_code& ec) const;
bool exists(LineInfo li, const fs::path& path) const;
// this should probably not exist, but would require a pass through of
// existing code to fix
bool exists(const fs::path& path) const;
bool exists(const fs::path& path, ignore_errors_t = ignore_errors) const;
virtual bool is_directory(const fs::path& path) const = 0;
virtual bool is_regular_file(const fs::path& path) const = 0;
virtual bool is_empty(const fs::path& path) const = 0;
virtual bool create_directory(const fs::path& path, std::error_code& ec) = 0;
bool create_directory(const fs::path& path, ignore_errors_t);
virtual bool create_directories(const fs::path& path, std::error_code& ec) = 0;
bool create_directories(const fs::path& path, ignore_errors_t);
virtual void copy(const fs::path& oldpath, const fs::path& newpath, fs::copy_options opts) = 0;
virtual bool copy_file(const fs::path& oldpath,
const fs::path& newpath,
Expand All @@ -149,9 +152,12 @@ namespace vcpkg::Files
virtual fs::file_status status(const fs::path& path, std::error_code& ec) const = 0;
virtual fs::file_status symlink_status(const fs::path& path, std::error_code& ec) const = 0;
fs::file_status status(LineInfo li, const fs::path& p) const noexcept;
fs::file_status status(const fs::path& p, ignore_errors_t) const noexcept;
fs::file_status symlink_status(LineInfo li, const fs::path& p) const noexcept;
fs::file_status symlink_status(const fs::path& p, ignore_errors_t) const noexcept;
virtual fs::path canonical(const fs::path& path, std::error_code& ec) const = 0;
fs::path canonical(LineInfo li, const fs::path& path) const;
fs::path canonical(const fs::path& path, ignore_errors_t) const;

virtual std::vector<fs::path> find_from_PATH(const std::string& name) const = 0;
};
Expand Down
10 changes: 10 additions & 0 deletions toolsrc/include/vcpkg/base/ignore_errors.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#pragma once

namespace vcpkg
{
struct ignore_errors_t
{
};

constexpr ignore_errors_t ignore_errors;
}
55 changes: 49 additions & 6 deletions toolsrc/src/vcpkg/base/files.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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
{
Expand Down Expand Up @@ -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)
{
Expand All @@ -444,7 +487,7 @@ namespace vcpkg::Files
}
}

copy_failure: ;
copy_failure:;
}
#endif
if (written_bytes == -1)
Expand Down
8 changes: 4 additions & 4 deletions toolsrc/src/vcpkg/binarycaching.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)
{
Expand Down Expand Up @@ -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()))
{
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions toolsrc/vcpkglib/vcpkglib.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@
<ClInclude Include="..\include\vcpkg\base\files.h" />
<ClInclude Include="..\include\vcpkg\base\graphs.h" />
<ClInclude Include="..\include\vcpkg\base\hash.h" />
<ClInclude Include="..\include\vcpkg\base\ignore_errors.h" />
<ClInclude Include="..\include\vcpkg\base\lazy.h" />
<ClInclude Include="..\include\vcpkg\base\lineinfo.h" />
<ClInclude Include="..\include\vcpkg\base\machinetype.h" />
Expand Down