[vcpkg] Alias out standard filesystem headers to ensure clean separation.

This commit is contained in:
Robert Schumacher 2017-04-11 15:16:39 -07:00
parent b34c40a4e6
commit 0bc21296c9
16 changed files with 128 additions and 88 deletions

View File

@ -2,4 +2,15 @@
#include <filesystem> #include <filesystem>
namespace fs = std::tr2::sys; namespace fs
{
namespace stdfs = std::tr2::sys;
using stdfs::path;
using stdfs::copy_options;
using stdfs::file_status;
inline bool is_regular_file(file_status s) { return stdfs::is_regular_file(s); }
inline bool is_directory(file_status s) { return stdfs::is_directory(s); }
inline bool status_known(file_status s) { return stdfs::status_known(s); }
}

View File

@ -15,14 +15,17 @@ namespace vcpkg::Files
virtual void write_all_lines(const fs::path& file_path, const std::vector<std::string>& lines) = 0; virtual void write_all_lines(const fs::path& file_path, const std::vector<std::string>& lines) = 0;
virtual void rename(const fs::path& oldpath, const fs::path& newpath) = 0; virtual void rename(const fs::path& oldpath, const fs::path& newpath) = 0;
virtual void remove(const fs::path& path) = 0; virtual bool remove(const fs::path& path) = 0;
virtual bool remove(const fs::path& path, std::error_code& ec) = 0;
virtual std::uintmax_t remove_all(const fs::path& path, std::error_code& ec) = 0;
virtual bool exists(const fs::path& path) const = 0; virtual bool exists(const fs::path& path) const = 0;
virtual bool is_directory(const fs::path& path) const = 0; virtual bool is_directory(const fs::path& path) const = 0;
virtual bool is_regular_file(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 is_empty(const fs::path& path) const = 0;
virtual bool create_directory(const fs::path& path, std::error_code& ec) = 0; virtual bool create_directory(const fs::path& path, std::error_code& ec) = 0;
virtual void copy(const fs::path& oldpath, const fs::path& newpath, fs::copy_options opts) = 0; virtual void copy(const fs::path& oldpath, const fs::path& newpath, fs::copy_options opts) = 0;
virtual void copy_file(const fs::path& oldpath, const fs::path& newpath, fs::copy_options opts, std::error_code& ec) = 0; virtual bool copy_file(const fs::path& oldpath, const fs::path& newpath, fs::copy_options opts, std::error_code& ec) = 0;
virtual fs::file_status status(const fs::path& path, std::error_code& ec) const = 0;
}; };
Filesystem& get_real_filesystem(); Filesystem& get_real_filesystem();

View File

@ -237,9 +237,8 @@ namespace vcpkg::Paragraphs
std::vector<SourceParagraph> load_all_ports(const Files::Filesystem& fs, const fs::path& ports_dir) std::vector<SourceParagraph> load_all_ports(const Files::Filesystem& fs, const fs::path& ports_dir)
{ {
std::vector<SourceParagraph> output; std::vector<SourceParagraph> output;
for (auto it = fs::directory_iterator(ports_dir); it != fs::directory_iterator(); ++it) for (auto&& path : fs.non_recursive_find_all_files_in_dir(ports_dir))
{ {
const fs::path& path = it->path();
Expected<SourceParagraph> source_paragraph = try_load_port(fs, path); Expected<SourceParagraph> source_paragraph = try_load_port(fs, path);
if (auto srcpgh = source_paragraph.get()) if (auto srcpgh = source_paragraph.get())
{ {

View File

@ -73,7 +73,7 @@ namespace vcpkg::PostBuildLint
return false; return false;
} }
static LintStatus check_for_files_in_include_directory(const std::map<BuildPolicies::Type, OptBoolT>& policies, const fs::path& package_dir) static LintStatus check_for_files_in_include_directory(const Files::Filesystem& fs, const std::map<BuildPolicies::Type, OptBoolT>& policies, const fs::path& package_dir)
{ {
if (contains_and_enabled(policies, BuildPolicies::EMPTY_INCLUDE_FOLDER)) if (contains_and_enabled(policies, BuildPolicies::EMPTY_INCLUDE_FOLDER))
{ {
@ -81,7 +81,7 @@ namespace vcpkg::PostBuildLint
} }
const fs::path include_dir = package_dir / "include"; const fs::path include_dir = package_dir / "include";
if (!fs::exists(include_dir) || fs::is_empty(include_dir)) if (!fs.exists(include_dir) || fs.is_empty(include_dir))
{ {
System::println(System::Color::warning, "The folder /include is empty. This indicates the library was not correctly installed."); System::println(System::Color::warning, "The folder /include is empty. This indicates the library was not correctly installed.");
return LintStatus::ERROR_DETECTED; return LintStatus::ERROR_DETECTED;
@ -657,7 +657,7 @@ namespace vcpkg::PostBuildLint
return error_count; return error_count;
} }
error_count += check_for_files_in_include_directory(build_info.policies, package_dir); error_count += check_for_files_in_include_directory(fs, build_info.policies, package_dir);
error_count += check_for_files_in_debug_include_directory(fs, package_dir); error_count += check_for_files_in_debug_include_directory(fs, package_dir);
error_count += check_for_files_in_debug_share_directory(fs, package_dir); error_count += check_for_files_in_debug_share_directory(fs, package_dir);
error_count += check_folder_lib_cmake(fs, package_dir, spec); error_count += check_folder_lib_cmake(fs, package_dir, spec);
@ -681,11 +681,13 @@ namespace vcpkg::PostBuildLint
error_count += check_matching_debug_and_release_binaries(debug_libs, release_libs); error_count += check_matching_debug_and_release_binaries(debug_libs, release_libs);
{
std::vector<fs::path> libs; std::vector<fs::path> libs;
libs.insert(libs.cend(), debug_libs.cbegin(), debug_libs.cend()); libs.insert(libs.cend(), debug_libs.cbegin(), debug_libs.cend());
libs.insert(libs.cend(), release_libs.cbegin(), release_libs.cend()); libs.insert(libs.cend(), release_libs.cbegin(), release_libs.cend());
error_count += check_lib_architecture(spec.target_triplet().architecture(), libs); error_count += check_lib_architecture(spec.target_triplet().architecture(), libs);
}
switch (build_info.library_linkage) switch (build_info.library_linkage)
{ {

View File

@ -156,7 +156,7 @@ namespace vcpkg
Expected<VcpkgPaths> VcpkgPaths::create(const fs::path& vcpkg_root_dir) Expected<VcpkgPaths> VcpkgPaths::create(const fs::path& vcpkg_root_dir)
{ {
std::error_code ec; std::error_code ec;
const fs::path canonical_vcpkg_root_dir = fs::canonical(vcpkg_root_dir, ec); const fs::path canonical_vcpkg_root_dir = fs::stdfs::canonical(vcpkg_root_dir, ec);
if (ec) if (ec)
{ {
return ec; return ec;
@ -214,10 +214,9 @@ namespace vcpkg
bool VcpkgPaths::is_valid_triplet(const Triplet& t) const bool VcpkgPaths::is_valid_triplet(const Triplet& t) const
{ {
auto it = fs::directory_iterator(this->triplets); for (auto&& path : get_filesystem().non_recursive_find_all_files_in_dir(this->triplets))
for (; it != fs::directory_iterator(); ++it)
{ {
std::string triplet_file_name = it->path().stem().generic_u8string(); std::string triplet_file_name = path.stem().generic_u8string();
if (t.canonical_name() == triplet_file_name) // TODO: fuzzy compare if (t.canonical_name() == triplet_file_name) // TODO: fuzzy compare
{ {
//t.value = triplet_file_name; // NOTE: uncomment when implementing fuzzy compare //t.value = triplet_file_name; // NOTE: uncomment when implementing fuzzy compare
@ -279,7 +278,7 @@ namespace vcpkg
// Skip any instances that do not have vcvarsall. // Skip any instances that do not have vcvarsall.
const fs::path vcvarsall_bat = vc_dir / "Auxiliary" / "Build" / "vcvarsall.bat"; const fs::path vcvarsall_bat = vc_dir / "Auxiliary" / "Build" / "vcvarsall.bat";
paths_examined.push_back(vcvarsall_bat); paths_examined.push_back(vcvarsall_bat);
if (!fs::exists(vcvarsall_bat)) if (!fs.exists(vcvarsall_bat))
continue; continue;
// Locate the "best" MSVC toolchain version // Locate the "best" MSVC toolchain version

View File

@ -10,9 +10,8 @@ namespace vcpkg::Commands::Cache
static std::vector<BinaryParagraph> read_all_binary_paragraphs(const VcpkgPaths& paths) static std::vector<BinaryParagraph> read_all_binary_paragraphs(const VcpkgPaths& paths)
{ {
std::vector<BinaryParagraph> output; std::vector<BinaryParagraph> output;
for (auto it = fs::directory_iterator(paths.packages); it != fs::directory_iterator(); ++it) for (auto&& path : paths.get_filesystem().non_recursive_find_all_files_in_dir(paths.packages))
{ {
const fs::path& path = it->path();
const Expected<std::unordered_map<std::string, std::string>> pghs = Paragraphs::get_single_paragraph(paths.get_filesystem(), path / "CONTROL"); const Expected<std::unordered_map<std::string, std::string>> pghs = Paragraphs::get_single_paragraph(paths.get_filesystem(), path / "CONTROL");
if (auto p = pghs.get()) if (auto p = pghs.get())
{ {

View File

@ -7,13 +7,15 @@ namespace vcpkg::Commands::Edit
{ {
void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths) void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths)
{ {
auto& fs = paths.get_filesystem();
static const std::string example = Commands::Help::create_example_string("edit zlib"); static const std::string example = Commands::Help::create_example_string("edit zlib");
args.check_exact_arg_count(1, example); args.check_exact_arg_count(1, example);
args.check_and_get_optional_command_arguments({}); args.check_and_get_optional_command_arguments({});
const std::string port_name = args.command_arguments.at(0); const std::string port_name = args.command_arguments.at(0);
const fs::path portpath = paths.ports / port_name; const fs::path portpath = paths.ports / port_name;
Checks::check_exit(VCPKG_LINE_INFO, fs::is_directory(portpath), R"(Could not find port named "%s")", port_name); Checks::check_exit(VCPKG_LINE_INFO, fs.is_directory(portpath), R"(Could not find port named "%s")", port_name);
// Find the user's selected editor // Find the user's selected editor
std::wstring env_EDITOR; std::wstring env_EDITOR;
@ -30,7 +32,7 @@ namespace vcpkg::Commands::Edit
if (env_EDITOR.empty()) if (env_EDITOR.empty())
{ {
const fs::path CODE_EXE_PATH = System::get_ProgramFiles_32_bit() / "Microsoft VS Code/Code.exe"; const fs::path CODE_EXE_PATH = System::get_ProgramFiles_32_bit() / "Microsoft VS Code/Code.exe";
if (fs::exists(CODE_EXE_PATH)) if (fs.exists(CODE_EXE_PATH))
{ {
env_EDITOR = CODE_EXE_PATH; env_EDITOR = CODE_EXE_PATH;
} }
@ -50,13 +52,13 @@ namespace vcpkg::Commands::Edit
if (auto c = code_installpath.get()) if (auto c = code_installpath.get())
{ {
auto p = fs::path(*c) / "Code.exe"; auto p = fs::path(*c) / "Code.exe";
if (fs::exists(p)) if (fs.exists(p))
{ {
env_EDITOR = p.native(); env_EDITOR = p.native();
break; break;
} }
auto p_insiders = fs::path(*c) / "Code - Insiders.exe"; auto p_insiders = fs::path(*c) / "Code - Insiders.exe";
if (fs::exists(p_insiders)) if (fs.exists(p_insiders))
{ {
env_EDITOR = p_insiders.native(); env_EDITOR = p_insiders.native();
break; break;

View File

@ -7,10 +7,9 @@ namespace vcpkg::Commands::Help
void help_topic_valid_triplet(const VcpkgPaths& paths) void help_topic_valid_triplet(const VcpkgPaths& paths)
{ {
System::println("Available architecture triplets:"); System::println("Available architecture triplets:");
auto it = fs::directory_iterator(paths.triplets); for (auto&& path : paths.get_filesystem().non_recursive_find_all_files_in_dir(paths.triplets))
for (; it != fs::directory_iterator(); ++it)
{ {
System::println(" %s", it->path().stem().filename().string()); System::println(" %s", path.stem().filename().string());
} }
} }

View File

@ -30,24 +30,24 @@ namespace vcpkg::Commands::Install
fs.create_directory(paths.installed / target_triplet_as_string, ec); fs.create_directory(paths.installed / target_triplet_as_string, ec);
output.push_back(Strings::format(R"(%s/)", target_triplet_as_string)); output.push_back(Strings::format(R"(%s/)", target_triplet_as_string));
// TODO: replace use of recursive_directory_iterator with filesystem abstraction. auto files = fs.recursive_find_all_files_in_dir(package_prefix_path);
for (auto it = fs::recursive_directory_iterator(package_prefix_path); it != fs::recursive_directory_iterator(); ++it) for (auto&& file : files)
{ {
auto status = it->status(ec); auto status = fs.status(file, ec);
if (ec) if (ec)
{ {
System::println(System::Color::error, "failed: %s: %s", it->path().u8string(), ec.message()); System::println(System::Color::error, "failed: %s: %s", file.u8string(), ec.message());
continue; continue;
} }
const std::string filename = it->path().filename().generic_string(); const std::string filename = file.filename().generic_string();
if (fs::is_regular_file(status) && (_stricmp(filename.c_str(), "CONTROL") == 0 || _stricmp(filename.c_str(), "BUILD_INFO") == 0)) if (fs::is_regular_file(status) && (_stricmp(filename.c_str(), "CONTROL") == 0 || _stricmp(filename.c_str(), "BUILD_INFO") == 0))
{ {
// Do not copy the control file // Do not copy the control file
continue; continue;
} }
const std::string suffix = it->path().generic_u8string().substr(prefix_length + 1); const std::string suffix = file.generic_u8string().substr(prefix_length + 1);
const fs::path target = paths.installed / target_triplet_as_string / suffix; const fs::path target = paths.installed / target_triplet_as_string / suffix;
if (fs::is_directory(status)) if (fs::is_directory(status))
@ -69,7 +69,7 @@ namespace vcpkg::Commands::Install
{ {
System::println(System::Color::warning, "File %s was already present and will be overwritten", target.u8string(), ec.message()); System::println(System::Color::warning, "File %s was already present and will be overwritten", target.u8string(), ec.message());
} }
fs.copy_file(*it, target, fs::copy_options::overwrite_existing, ec); fs.copy_file(file, target, fs::copy_options::overwrite_existing, ec);
if (ec) if (ec)
{ {
System::println(System::Color::error, "failed: %s: %s", target.u8string(), ec.message()); System::println(System::Color::error, "failed: %s: %s", target.u8string(), ec.message());
@ -80,11 +80,11 @@ namespace vcpkg::Commands::Install
if (!fs::status_known(status)) if (!fs::status_known(status))
{ {
System::println(System::Color::error, "failed: %s: unknown status", it->path().u8string()); System::println(System::Color::error, "failed: %s: unknown status", file.u8string());
continue; continue;
} }
System::println(System::Color::error, "failed: %s: cannot handle file type", it->path().u8string()); System::println(System::Color::error, "failed: %s: cannot handle file type", file.u8string());
} }
std::sort(output.begin(), output.end()); std::sort(output.begin(), output.end());

View File

@ -141,10 +141,12 @@ namespace vcpkg::Commands::Integrate
static void integrate_install(const VcpkgPaths& paths) static void integrate_install(const VcpkgPaths& paths)
{ {
auto& fs = paths.get_filesystem();
// TODO: This block of code should eventually be removed // TODO: This block of code should eventually be removed
for (auto&& old_system_wide_targets_file : old_system_target_files) for (auto&& old_system_wide_targets_file : old_system_target_files)
{ {
if (fs::exists(old_system_wide_targets_file)) if (fs.exists(old_system_wide_targets_file))
{ {
const std::string param = Strings::format(R"(/c DEL "%s" /Q > nul)", old_system_wide_targets_file.string()); const std::string param = Strings::format(R"(/c DEL "%s" /Q > nul)", old_system_wide_targets_file.string());
ElevationPromptChoice user_choice = elevated_cmd_execute(param); ElevationPromptChoice user_choice = elevated_cmd_execute(param);
@ -161,12 +163,13 @@ namespace vcpkg::Commands::Integrate
} }
} }
std::error_code ec;
const fs::path tmp_dir = paths.buildsystems / "tmp"; const fs::path tmp_dir = paths.buildsystems / "tmp";
fs::create_directory(paths.buildsystems); fs.create_directory(paths.buildsystems, ec);
fs::create_directory(tmp_dir); fs.create_directory(tmp_dir, ec);
bool should_install_system = true; bool should_install_system = true;
const Expected<std::string> system_wide_file_contents = paths.get_filesystem().read_contents(system_wide_targets_file); const Expected<std::string> system_wide_file_contents = fs.read_contents(system_wide_targets_file);
if (auto contents_data = system_wide_file_contents.get()) if (auto contents_data = system_wide_file_contents.get())
{ {
std::regex re(R"###(<!-- version (\d+) -->)###"); std::regex re(R"###(<!-- version (\d+) -->)###");
@ -198,14 +201,16 @@ namespace vcpkg::Commands::Integrate
Checks::unreachable(VCPKG_LINE_INFO); Checks::unreachable(VCPKG_LINE_INFO);
} }
Checks::check_exit(VCPKG_LINE_INFO, fs::exists(system_wide_targets_file), "Error: failed to copy targets file to %s", system_wide_targets_file.string()); Checks::check_exit(VCPKG_LINE_INFO, fs.exists(system_wide_targets_file), "Error: failed to copy targets file to %s", system_wide_targets_file.string());
} }
const fs::path appdata_src_path = tmp_dir / "vcpkg.user.targets"; const fs::path appdata_src_path = tmp_dir / "vcpkg.user.targets";
std::ofstream(appdata_src_path) << create_appdata_targets_shortcut(paths.buildsystems_msbuild_targets.string()); std::ofstream(appdata_src_path) << create_appdata_targets_shortcut(paths.buildsystems_msbuild_targets.string());
auto appdata_dst_path = get_appdata_targets_path(); auto appdata_dst_path = get_appdata_targets_path();
if (!fs::copy_file(appdata_src_path, appdata_dst_path, fs::copy_options::overwrite_existing)) auto rc = fs.copy_file(appdata_src_path, appdata_dst_path, fs::copy_options::overwrite_existing, ec);
if (!rc || ec)
{ {
System::println(System::Color::error, "Error: Failed to copy file: %s -> %s", appdata_src_path.string(), appdata_dst_path.string()); System::println(System::Color::error, "Error: Failed to copy file: %s -> %s", appdata_src_path.string(), appdata_dst_path.string());
Checks::exit_fail(VCPKG_LINE_INFO); Checks::exit_fail(VCPKG_LINE_INFO);
@ -222,12 +227,12 @@ namespace vcpkg::Commands::Integrate
Checks::exit_success(VCPKG_LINE_INFO); Checks::exit_success(VCPKG_LINE_INFO);
} }
static void integrate_remove() static void integrate_remove(Files::Filesystem& fs)
{ {
const fs::path path = get_appdata_targets_path(); const fs::path path = get_appdata_targets_path();
std::error_code ec; std::error_code ec;
bool was_deleted = fs::remove(path, ec); bool was_deleted = fs.remove(path, ec);
Checks::check_exit(VCPKG_LINE_INFO, !ec, "Error: Unable to remove user-wide integration: %d", ec.message()); Checks::check_exit(VCPKG_LINE_INFO, !ec, "Error: Unable to remove user-wide integration: %d", ec.message());
@ -245,12 +250,15 @@ namespace vcpkg::Commands::Integrate
static void integrate_project(const VcpkgPaths& paths) static void integrate_project(const VcpkgPaths& paths)
{ {
auto& fs = paths.get_filesystem();
const fs::path& nuget_exe = paths.get_nuget_exe(); const fs::path& nuget_exe = paths.get_nuget_exe();
const fs::path& buildsystems_dir = paths.buildsystems; const fs::path& buildsystems_dir = paths.buildsystems;
const fs::path tmp_dir = buildsystems_dir / "tmp"; const fs::path tmp_dir = buildsystems_dir / "tmp";
fs::create_directory(buildsystems_dir); std::error_code ec;
fs::create_directory(tmp_dir); fs.create_directory(buildsystems_dir, ec);
fs.create_directory(tmp_dir, ec);
const fs::path targets_file_path = tmp_dir / "vcpkg.nuget.targets"; const fs::path targets_file_path = tmp_dir / "vcpkg.nuget.targets";
const fs::path props_file_path = tmp_dir / "vcpkg.nuget.props"; const fs::path props_file_path = tmp_dir / "vcpkg.nuget.props";
@ -268,7 +276,7 @@ namespace vcpkg::Commands::Integrate
const int exit_code = System::cmd_execute_clean(cmd_line); const int exit_code = System::cmd_execute_clean(cmd_line);
const fs::path nuget_package = buildsystems_dir / Strings::format("%s.%s.nupkg", nuget_id, nupkg_version); const fs::path nuget_package = buildsystems_dir / Strings::format("%s.%s.nupkg", nuget_id, nupkg_version);
Checks::check_exit(VCPKG_LINE_INFO, exit_code == 0 && fs::exists(nuget_package), "Error: NuGet package creation failed"); Checks::check_exit(VCPKG_LINE_INFO, exit_code == 0 && fs.exists(nuget_package), "Error: NuGet package creation failed");
System::println(System::Color::success, "Created nupkg: %s", nuget_package.string()); System::println(System::Color::success, "Created nupkg: %s", nuget_package.string());
System::println(R"( System::println(R"(
@ -297,7 +305,7 @@ With a project open, go to Tools->NuGet Package Manager->Package Manager Console
} }
if (args.command_arguments[0] == "remove") if (args.command_arguments[0] == "remove")
{ {
return integrate_remove(); return integrate_remove(paths.get_filesystem());
} }
if (args.command_arguments[0] == "project") if (args.command_arguments[0] == "project")
{ {

View File

@ -69,11 +69,13 @@ namespace vcpkg::Commands::PortsDiff
static std::map<std::string, VersionT> read_ports_from_commit(const VcpkgPaths& paths, const std::wstring& git_commit_id) static std::map<std::string, VersionT> read_ports_from_commit(const VcpkgPaths& paths, const std::wstring& git_commit_id)
{ {
std::error_code ec;
auto& fs = paths.get_filesystem();
const fs::path& git_exe = paths.get_git_exe(); const fs::path& git_exe = paths.get_git_exe();
const fs::path dot_git_dir = paths.root / ".git"; const fs::path dot_git_dir = paths.root / ".git";
const std::wstring ports_dir_name_as_string = paths.ports.filename().native(); const std::wstring ports_dir_name_as_string = paths.ports.filename().native();
const fs::path temp_checkout_path = paths.root / Strings::wformat(L"%s-%s", ports_dir_name_as_string, git_commit_id); const fs::path temp_checkout_path = paths.root / Strings::wformat(L"%s-%s", ports_dir_name_as_string, git_commit_id);
fs::create_directory(temp_checkout_path); fs.create_directory(temp_checkout_path, ec);
const std::wstring checkout_this_dir = Strings::wformat(LR"(.\%s)", ports_dir_name_as_string); // Must be relative to the root of the repository const std::wstring checkout_this_dir = Strings::wformat(LR"(.\%s)", ports_dir_name_as_string); // Must be relative to the root of the repository
const std::wstring cmd = Strings::wformat(LR"("%s" --git-dir="%s" --work-tree="%s" checkout %s -f -q -- %s %s & "%s" reset >NUL)", const std::wstring cmd = Strings::wformat(LR"("%s" --git-dir="%s" --work-tree="%s" checkout %s -f -q -- %s %s & "%s" reset >NUL)",
@ -87,7 +89,7 @@ namespace vcpkg::Commands::PortsDiff
System::cmd_execute_clean(cmd); System::cmd_execute_clean(cmd);
const std::vector<SourceParagraph> source_paragraphs = Paragraphs::load_all_ports(paths.get_filesystem(), temp_checkout_path / ports_dir_name_as_string); const std::vector<SourceParagraph> source_paragraphs = Paragraphs::load_all_ports(paths.get_filesystem(), temp_checkout_path / ports_dir_name_as_string);
const std::map<std::string, VersionT> names_and_versions = Paragraphs::extract_port_names_and_versions(source_paragraphs); const std::map<std::string, VersionT> names_and_versions = Paragraphs::extract_port_names_and_versions(source_paragraphs);
fs::remove_all(temp_checkout_path); fs.remove_all(temp_checkout_path, ec);
return names_and_versions; return names_and_versions;
} }

View File

@ -13,15 +13,15 @@ namespace vcpkg::Commands::Remove
using Dependencies::RequestType; using Dependencies::RequestType;
using Update::OutdatedPackage; using Update::OutdatedPackage;
static void delete_directory(const fs::path& directory) static void delete_directory(Files::Filesystem& fs, const fs::path& directory)
{ {
std::error_code ec; std::error_code ec;
fs::remove_all(directory, ec); fs.remove_all(directory, ec);
if (!ec) if (!ec)
{ {
System::println(System::Color::success, "Cleaned up %s", directory.string()); System::println(System::Color::success, "Cleaned up %s", directory.string());
} }
if (fs::exists(directory)) if (fs.exists(directory))
{ {
System::println(System::Color::warning, "Some files in %s were unable to be removed. Close any editors operating in this directory and retry.", directory.string()); System::println(System::Color::warning, "Some files in %s were unable to be removed. Close any editors operating in this directory and retry.", directory.string());
} }
@ -29,18 +29,19 @@ namespace vcpkg::Commands::Remove
static void remove_package(const VcpkgPaths& paths, const PackageSpec& spec, StatusParagraphs* status_db) static void remove_package(const VcpkgPaths& paths, const PackageSpec& spec, StatusParagraphs* status_db)
{ {
auto& fs = paths.get_filesystem();
StatusParagraph& pkg = **status_db->find(spec.name(), spec.target_triplet()); StatusParagraph& pkg = **status_db->find(spec.name(), spec.target_triplet());
pkg.want = Want::PURGE; pkg.want = Want::PURGE;
pkg.state = InstallState::HALF_INSTALLED; pkg.state = InstallState::HALF_INSTALLED;
write_update(paths, pkg); write_update(paths, pkg);
std::fstream listfile(paths.listfile_path(pkg.package), std::ios_base::in | std::ios_base::binary); auto maybe_lines = fs.read_all_lines(paths.listfile_path(pkg.package));
if (listfile)
if (auto lines = maybe_lines.get())
{ {
std::vector<fs::path> dirs_touched; std::vector<fs::path> dirs_touched;
std::string suffix; for (auto&& suffix : *lines)
while (std::getline(listfile, suffix))
{ {
if (!suffix.empty() && suffix.back() == '\r') if (!suffix.empty() && suffix.back() == '\r')
suffix.pop_back(); suffix.pop_back();
@ -49,7 +50,7 @@ namespace vcpkg::Commands::Remove
auto target = paths.installed / suffix; auto target = paths.installed / suffix;
auto status = fs::status(target, ec); auto status = fs.status(target, ec);
if (ec) if (ec)
{ {
System::println(System::Color::error, "failed: %s", ec.message()); System::println(System::Color::error, "failed: %s", ec.message());
@ -62,7 +63,7 @@ namespace vcpkg::Commands::Remove
} }
else if (fs::is_regular_file(status)) else if (fs::is_regular_file(status))
{ {
fs::remove(target, ec); fs.remove(target, ec);
if (ec) if (ec)
{ {
System::println(System::Color::error, "failed: %s: %s", target.u8string(), ec.message()); System::println(System::Color::error, "failed: %s: %s", target.u8string(), ec.message());
@ -82,10 +83,10 @@ namespace vcpkg::Commands::Remove
auto e = dirs_touched.rend(); auto e = dirs_touched.rend();
for (; b != e; ++b) for (; b != e; ++b)
{ {
if (fs::directory_iterator(*b) == fs::directory_iterator()) if (fs.is_empty(*b))
{ {
std::error_code ec; std::error_code ec;
fs::remove(*b, ec); fs.remove(*b, ec);
if (ec) if (ec)
{ {
System::println(System::Color::error, "failed: %s", ec.message()); System::println(System::Color::error, "failed: %s", ec.message());
@ -93,8 +94,7 @@ namespace vcpkg::Commands::Remove
} }
} }
listfile.close(); fs.remove(paths.listfile_path(pkg.package));
fs::remove(paths.listfile_path(pkg.package));
} }
pkg.state = InstallState::NOT_INSTALLED; pkg.state = InstallState::NOT_INSTALLED;
@ -220,7 +220,7 @@ namespace vcpkg::Commands::Remove
if (alsoRemoveFolderFromPackages) if (alsoRemoveFolderFromPackages)
{ {
System::println("Purging package %s... ", display_name); System::println("Purging package %s... ", display_name);
delete_directory(paths.packages / action.spec.dir()); delete_directory(paths.get_filesystem(), paths.packages / action.spec.dir());
System::println(System::Color::success, "Purging package %s... done", display_name); System::println(System::Color::success, "Purging package %s... done", display_name);
} }
} }

View File

@ -3,6 +3,7 @@
#include "filesystem_fs.h" #include "filesystem_fs.h"
#include "vcpkg_Strings.h" #include "vcpkg_Strings.h"
#include "vcpkg_System.h" #include "vcpkg_System.h"
#include "vcpkg_Files.h"
namespace vcpkg::Metrics namespace vcpkg::Metrics
{ {
@ -385,24 +386,26 @@ true
const fs::path temp_folder_path = temp_folder; const fs::path temp_folder_path = temp_folder;
const fs::path temp_folder_path_exe = temp_folder_path / "vcpkgmetricsuploader.exe"; const fs::path temp_folder_path_exe = temp_folder_path / "vcpkgmetricsuploader.exe";
auto& fs = Files::get_real_filesystem();
if (true) if (true)
{ {
const fs::path exe_path = []() -> fs::path const fs::path exe_path = [&fs]() -> fs::path
{ {
auto vcpkgdir = get_bindir().parent_path(); auto vcpkgdir = get_bindir().parent_path();
auto path = vcpkgdir / "vcpkgmetricsuploader.exe"; auto path = vcpkgdir / "vcpkgmetricsuploader.exe";
if (fs::exists(path)) if (fs.exists(path))
return path; return path;
path = vcpkgdir / "scripts" / "vcpkgmetricsuploader.exe"; path = vcpkgdir / "scripts" / "vcpkgmetricsuploader.exe";
if (fs::exists(path)) if (fs.exists(path))
return path; return path;
return L""; return L"";
}(); }();
std::error_code ec; std::error_code ec;
fs::copy_file(exe_path, temp_folder_path_exe, fs::copy_options::skip_existing, ec); fs.copy_file(exe_path, temp_folder_path_exe, fs::copy_options::skip_existing, ec);
if (ec) if (ec)
return; return;
} }

View File

@ -41,18 +41,18 @@ static void inner(const VcpkgCmdArguments& args)
fs::path vcpkg_root_dir; fs::path vcpkg_root_dir;
if (args.vcpkg_root_dir != nullptr) if (args.vcpkg_root_dir != nullptr)
{ {
vcpkg_root_dir = fs::absolute(Strings::utf8_to_utf16(*args.vcpkg_root_dir)); vcpkg_root_dir = fs::stdfs::absolute(Strings::utf8_to_utf16(*args.vcpkg_root_dir));
} }
else else
{ {
const Optional<std::wstring> vcpkg_root_dir_env = System::get_environmental_variable(L"VCPKG_ROOT"); const Optional<std::wstring> vcpkg_root_dir_env = System::get_environmental_variable(L"VCPKG_ROOT");
if (auto v = vcpkg_root_dir_env.get()) if (auto v = vcpkg_root_dir_env.get())
{ {
vcpkg_root_dir = fs::absolute(*v); vcpkg_root_dir = fs::stdfs::absolute(*v);
} }
else else
{ {
vcpkg_root_dir = Files::get_real_filesystem().find_file_recursively_up(fs::absolute(System::get_exe_path_of_current_process()), ".vcpkg-root"); vcpkg_root_dir = Files::get_real_filesystem().find_file_recursively_up(fs::stdfs::absolute(System::get_exe_path_of_current_process()), ".vcpkg-root");
} }
} }
@ -144,7 +144,7 @@ static void loadConfig()
try try
{ {
std::error_code ec; std::error_code ec;
fs::create_directory(localappdata / "vcpkg", ec); Files::get_real_filesystem().create_directory(localappdata / "vcpkg", ec);
std::ofstream(localappdata / "vcpkg" / "config", std::ios_base::out | std::ios_base::trunc) std::ofstream(localappdata / "vcpkg" / "config", std::ios_base::out | std::ios_base::trunc)
<< "User-Id: " << user_id << "\n" << "User-Id: " << user_id << "\n"
<< "User-Since: " << user_time << "\n"; << "User-Since: " << user_time << "\n";

View File

@ -56,7 +56,7 @@ namespace vcpkg::Files
for (; !current_dir.empty(); current_dir = current_dir.parent_path()) for (; !current_dir.empty(); current_dir = current_dir.parent_path())
{ {
const fs::path candidate = current_dir / filename; const fs::path candidate = current_dir / filename;
if (fs::exists(candidate)) if (exists(candidate))
{ {
break; break;
} }
@ -69,7 +69,7 @@ namespace vcpkg::Files
{ {
std::vector<fs::path> ret; std::vector<fs::path> ret;
fs::recursive_directory_iterator b(dir), e{}; fs::stdfs::recursive_directory_iterator b(dir), e{};
for (; b != e; ++b) for (; b != e; ++b)
{ {
ret.push_back(b->path()); ret.push_back(b->path());
@ -81,7 +81,7 @@ namespace vcpkg::Files
{ {
std::vector<fs::path> ret; std::vector<fs::path> ret;
fs::directory_iterator b(dir), e{}; fs::stdfs::directory_iterator b(dir), e{};
for (; b != e; ++b) for (; b != e; ++b)
{ {
ret.push_back(b->path()); ret.push_back(b->path());
@ -102,39 +102,52 @@ namespace vcpkg::Files
virtual void rename(const fs::path & oldpath, const fs::path & newpath) override virtual void rename(const fs::path & oldpath, const fs::path & newpath) override
{ {
fs::rename(oldpath, newpath); fs::stdfs::rename(oldpath, newpath);
} }
virtual void remove(const fs::path & path) override virtual bool remove(const fs::path & path) override
{ {
fs::remove(path); return fs::stdfs::remove(path);
}
virtual bool remove(const fs::path & path, std::error_code& ec) override
{
return fs::stdfs::remove(path, ec);
}
virtual std::uintmax_t remove_all(const fs::path & path, std::error_code& ec) override
{
return fs::stdfs::remove_all(path, ec);
} }
virtual bool exists(const fs::path & path) const override virtual bool exists(const fs::path & path) const override
{ {
return fs::exists(path); return fs::stdfs::exists(path);
} }
virtual bool is_directory(const fs::path & path) const override virtual bool is_directory(const fs::path & path) const override
{ {
return fs::is_directory(path); return fs::stdfs::is_directory(path);
} }
virtual bool is_regular_file(const fs::path & path) const override virtual bool is_regular_file(const fs::path & path) const override
{ {
return fs::is_regular_file(path); return fs::stdfs::is_regular_file(path);
} }
virtual bool is_empty(const fs::path & path) const override virtual bool is_empty(const fs::path & path) const override
{ {
return fs::is_empty(path); return fs::stdfs::is_empty(path);
} }
virtual bool create_directory(const fs::path & path, std::error_code & ec) override virtual bool create_directory(const fs::path & path, std::error_code & ec) override
{ {
return fs::create_directory(path, ec); return fs::stdfs::create_directory(path, ec);
} }
virtual void copy(const fs::path & oldpath, const fs::path & newpath, fs::copy_options opts) override virtual void copy(const fs::path & oldpath, const fs::path & newpath, fs::copy_options opts) override
{ {
fs::copy(oldpath, newpath, opts); fs::stdfs::copy(oldpath, newpath, opts);
} }
virtual void copy_file(const fs::path & oldpath, const fs::path & newpath, fs::copy_options opts, std::error_code & ec) override virtual bool copy_file(const fs::path & oldpath, const fs::path & newpath, fs::copy_options opts, std::error_code & ec) override
{ {
fs::copy_file(oldpath, newpath, opts, ec); return fs::stdfs::copy_file(oldpath, newpath, opts, ec);
}
virtual fs::file_status status(const fs::path& path, std::error_code& ec) const override
{
return fs::stdfs::status(path, ec);
} }
}; };

View File

@ -12,15 +12,15 @@ namespace vcpkg
static StatusParagraphs load_current_database(Files::Filesystem& fs, const fs::path& vcpkg_dir_status_file, const fs::path& vcpkg_dir_status_file_old) static StatusParagraphs load_current_database(Files::Filesystem& fs, const fs::path& vcpkg_dir_status_file, const fs::path& vcpkg_dir_status_file_old)
{ {
if (!fs::exists(vcpkg_dir_status_file)) if (!fs.exists(vcpkg_dir_status_file))
{ {
if (!fs::exists(vcpkg_dir_status_file_old)) if (!fs.exists(vcpkg_dir_status_file_old))
{ {
// no status file, use empty db // no status file, use empty db
return StatusParagraphs(); return StatusParagraphs();
} }
fs::rename(vcpkg_dir_status_file_old, vcpkg_dir_status_file); fs.rename(vcpkg_dir_status_file_old, vcpkg_dir_status_file);
} }
auto pghs = Paragraphs::get_paragraphs(fs, vcpkg_dir_status_file).value_or_exit(VCPKG_LINE_INFO); auto pghs = Paragraphs::get_paragraphs(fs, vcpkg_dir_status_file).value_or_exit(VCPKG_LINE_INFO);