diff options
| author | Robert Schumacher <roschuma@microsoft.com> | 2017-04-14 16:07:54 -0700 |
|---|---|---|
| committer | Robert Schumacher <roschuma@microsoft.com> | 2017-04-14 16:07:54 -0700 |
| commit | 20397fc845fac398a1aca2ee17ce5b932fc1a83b (patch) | |
| tree | 51235bc2602a81a89da9605272a37ca4fc1765a8 /toolsrc/src/commands_integrate.cpp | |
| parent | 8183671a492aa21ec20780a77f923848b0aeca41 (diff) | |
| parent | 1c08a42091cb0addd1e0c1daf27d24bf4e9d237f (diff) | |
| download | vcpkg-20397fc845fac398a1aca2ee17ce5b932fc1a83b.tar.gz vcpkg-20397fc845fac398a1aca2ee17ce5b932fc1a83b.zip | |
Merge branch 'dev/roschuma/fs-testing'
Diffstat (limited to 'toolsrc/src/commands_integrate.cpp')
| -rw-r--r-- | toolsrc/src/commands_integrate.cpp | 42 |
1 files changed, 25 insertions, 17 deletions
diff --git a/toolsrc/src/commands_integrate.cpp b/toolsrc/src/commands_integrate.cpp index ea0682e1f..5772843df 100644 --- a/toolsrc/src/commands_integrate.cpp +++ b/toolsrc/src/commands_integrate.cpp @@ -139,10 +139,12 @@ namespace vcpkg::Commands::Integrate static void integrate_install(const VcpkgPaths& paths) { + auto& fs = paths.get_filesystem(); + // TODO: This block of code should eventually be removed 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()); ElevationPromptChoice user_choice = elevated_cmd_execute(param); @@ -159,12 +161,13 @@ namespace vcpkg::Commands::Integrate } } + std::error_code ec; const fs::path tmp_dir = paths.buildsystems / "tmp"; - fs::create_directory(paths.buildsystems); - fs::create_directory(tmp_dir); + fs.create_directory(paths.buildsystems, ec); + fs.create_directory(tmp_dir, ec); bool should_install_system = true; - const Expected<std::string> system_wide_file_contents = Files::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()) { std::regex re(R"###(<!-- version (\d+) -->)###"); @@ -181,7 +184,7 @@ namespace vcpkg::Commands::Integrate if (should_install_system) { const fs::path sys_src_path = tmp_dir / "vcpkg.system.targets"; - std::ofstream(sys_src_path) << create_system_targets_shortcut(); + fs.write_contents(sys_src_path, create_system_targets_shortcut()); const std::string param = Strings::format(R"(/c mkdir "%s" & copy "%s" "%s" /Y > nul)", system_wide_targets_file.parent_path().string(), sys_src_path.string(), system_wide_targets_file.string()); ElevationPromptChoice user_choice = elevated_cmd_execute(param); @@ -196,14 +199,16 @@ namespace vcpkg::Commands::Integrate 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"; - std::ofstream(appdata_src_path) << create_appdata_targets_shortcut(paths.buildsystems_msbuild_targets.string()); + fs.write_contents(appdata_src_path, create_appdata_targets_shortcut(paths.buildsystems_msbuild_targets.string())); 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()); Checks::exit_fail(VCPKG_LINE_INFO); @@ -220,12 +225,12 @@ namespace vcpkg::Commands::Integrate 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(); 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()); @@ -243,12 +248,15 @@ namespace vcpkg::Commands::Integrate static void integrate_project(const VcpkgPaths& paths) { + auto& fs = paths.get_filesystem(); + const fs::path& nuget_exe = paths.get_nuget_exe(); const fs::path& buildsystems_dir = paths.buildsystems; const fs::path tmp_dir = buildsystems_dir / "tmp"; - fs::create_directory(buildsystems_dir); - fs::create_directory(tmp_dir); + std::error_code ec; + 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 props_file_path = tmp_dir / "vcpkg.nuget.props"; @@ -256,9 +264,9 @@ namespace vcpkg::Commands::Integrate const std::string nuget_id = get_nuget_id(paths.root); const std::string nupkg_version = "1.0.0"; - std::ofstream(targets_file_path) << create_nuget_targets_file(paths.buildsystems_msbuild_targets); - std::ofstream(props_file_path) << create_nuget_props_file(); - std::ofstream(nuspec_file_path) << create_nuspec_file(paths.root, nuget_id, nupkg_version); + fs.write_contents(targets_file_path, create_nuget_targets_file(paths.buildsystems_msbuild_targets)); + fs.write_contents(props_file_path, create_nuget_props_file()); + fs.write_contents(nuspec_file_path, create_nuspec_file(paths.root, nuget_id, nupkg_version)); // Using all forward slashes for the command line const std::wstring cmd_line = Strings::wformat(LR"("%s" pack -OutputDirectory "%s" "%s" > nul)", nuget_exe.native(), buildsystems_dir.native(), nuspec_file_path.native()); @@ -266,7 +274,7 @@ namespace vcpkg::Commands::Integrate 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); - 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(R"( @@ -295,7 +303,7 @@ With a project open, go to Tools->NuGet Package Manager->Package Manager Console } if (args.command_arguments[0] == "remove") { - return integrate_remove(); + return integrate_remove(paths.get_filesystem()); } if (args.command_arguments[0] == "project") { |
