From 46c0e22def4deef5a0c937f65d9d6d7cfd8d37ce Mon Sep 17 00:00:00 2001 From: Billy O'Neal Date: Wed, 31 May 2023 01:33:49 -0700 Subject: [PATCH] Fix binary caching for 'upgrade'd packages (#1083) --- include/vcpkg/commands.install.h | 2 ++ src/vcpkg/commands.ci.cpp | 1 + src/vcpkg/commands.install.cpp | 18 ++++++++++++++++-- src/vcpkg/commands.remove.cpp | 4 ++-- src/vcpkg/commands.set-installed.cpp | 1 + src/vcpkg/postbuildlint.cpp | 2 +- 6 files changed, 23 insertions(+), 5 deletions(-) diff --git a/include/vcpkg/commands.install.h b/include/vcpkg/commands.install.h index 6d4cff0bc0..197d7f0af0 100644 --- a/include/vcpkg/commands.install.h +++ b/include/vcpkg/commands.install.h @@ -92,6 +92,8 @@ namespace vcpkg const Filesystem& fs, const InstalledPaths& installed); + void preclear_packages(const VcpkgPaths& paths, const ActionPlan& action_plan); + InstallSummary execute_plan(const VcpkgCmdArguments& args, const ActionPlan& action_plan, const KeepGoing keep_going, diff --git a/src/vcpkg/commands.ci.cpp b/src/vcpkg/commands.ci.cpp index ec897f6ee7..a50aac133d 100644 --- a/src/vcpkg/commands.ci.cpp +++ b/src/vcpkg/commands.ci.cpp @@ -514,6 +514,7 @@ namespace vcpkg::Commands::CI { msg::println_warning(msgCISkipInstallation, msg::list = Strings::join(", ", already_installed)); } + Install::preclear_packages(paths, action_plan); binary_cache.fetch(action_plan.install_actions); auto summary = Install::execute_plan( args, action_plan, KeepGoing::YES, paths, status_db, binary_cache, build_logs_recorder); diff --git a/src/vcpkg/commands.install.cpp b/src/vcpkg/commands.install.cpp index b829347b4d..f92fd54a12 100644 --- a/src/vcpkg/commands.install.cpp +++ b/src/vcpkg/commands.install.cpp @@ -285,7 +285,7 @@ namespace vcpkg const InstallDir install_dir = InstallDir::from_destination_root(paths.installed(), triplet, bcf.core_paragraph); - install_package_and_write_listfile(fs, paths.package_dir(bcf.core_paragraph.spec), install_dir); + install_package_and_write_listfile(fs, package_dir, install_dir); source_paragraph.state = InstallState::INSTALLED; write_update(fs, installed, source_paragraph); @@ -514,6 +514,20 @@ namespace vcpkg TrackedPackageInstallGuard& operator=(const TrackedPackageInstallGuard&) = delete; }; + void Install::preclear_packages(const VcpkgPaths& paths, const ActionPlan& action_plan) + { + auto& fs = paths.get_filesystem(); + for (auto&& action : action_plan.remove_actions) + { + fs.remove_all(paths.package_dir(action.spec), VCPKG_LINE_INFO); + } + + for (auto&& action : action_plan.install_actions) + { + fs.remove_all(action.package_dir.value_or_exit(VCPKG_LINE_INFO), VCPKG_LINE_INFO); + } + } + InstallSummary Install::execute_plan(const VcpkgCmdArguments& args, const ActionPlan& action_plan, const KeepGoing keep_going, @@ -532,7 +546,6 @@ namespace vcpkg { TrackedPackageInstallGuard this_install(action_index++, action_count, results, action); Remove::remove_package(fs, paths.installed(), action.spec, status_db); - fs.remove_all(paths.packages() / action.spec.dir(), VCPKG_LINE_INFO); results.back().build_result.emplace(BuildResult::REMOVED); } @@ -1270,6 +1283,7 @@ namespace vcpkg paths.flush_lockfile(); track_install_plan(action_plan); + Install::preclear_packages(paths, action_plan); auto binary_cache = only_downloads ? BinaryCache(paths.get_filesystem()) : BinaryCache::make(args, paths, stdout_sink).value_or_exit(VCPKG_LINE_INFO); diff --git a/src/vcpkg/commands.remove.cpp b/src/vcpkg/commands.remove.cpp index 4987250568..ceb3c6a36c 100644 --- a/src/vcpkg/commands.remove.cpp +++ b/src/vcpkg/commands.remove.cpp @@ -288,7 +288,7 @@ namespace vcpkg::Remove { for (auto&& action : plan.not_installed) { - fs.remove_all(paths.packages() / action.spec.dir(), VCPKG_LINE_INFO); + fs.remove_all(paths.package_dir(action.spec), VCPKG_LINE_INFO); } } @@ -302,7 +302,7 @@ namespace vcpkg::Remove remove_package(fs, paths.installed(), action.spec, status_db); if (purge == Purge::YES) { - fs.remove_all(paths.packages() / action.spec.dir(), VCPKG_LINE_INFO); + fs.remove_all(paths.package_dir(action.spec), VCPKG_LINE_INFO); } } diff --git a/src/vcpkg/commands.set-installed.cpp b/src/vcpkg/commands.set-installed.cpp index a41ac36751..d17c5c4617 100644 --- a/src/vcpkg/commands.set-installed.cpp +++ b/src/vcpkg/commands.set-installed.cpp @@ -131,6 +131,7 @@ namespace vcpkg::Commands::SetInstalled paths.flush_lockfile(); track_install_plan(action_plan); + Install::preclear_packages(paths, action_plan); auto binary_cache = only_downloads ? BinaryCache(paths.get_filesystem()) : BinaryCache::make(args, paths, stdout_sink).value_or_exit(VCPKG_LINE_INFO); diff --git a/src/vcpkg/postbuildlint.cpp b/src/vcpkg/postbuildlint.cpp index 35867b4d84..cb54e64c32 100644 --- a/src/vcpkg/postbuildlint.cpp +++ b/src/vcpkg/postbuildlint.cpp @@ -354,7 +354,7 @@ namespace vcpkg const VcpkgPaths& paths, MessageSink& msg_sink) { - const auto packages_dir = paths.packages() / spec.dir(); + const auto packages_dir = paths.package_dir(spec); const auto copyright_file = packages_dir / "share" / spec.name() / "copyright"; switch (fs.status(copyright_file, IgnoreErrors{}))