@@ -285,7 +285,7 @@ namespace vcpkg
285285 const InstallDir install_dir =
286286 InstallDir::from_destination_root (paths.installed (), triplet, bcf.core_paragraph );
287287
288- install_package_and_write_listfile (fs, paths. package_dir (bcf. core_paragraph . spec ) , install_dir);
288+ install_package_and_write_listfile (fs, package_dir, install_dir);
289289
290290 source_paragraph.state = InstallState::INSTALLED;
291291 write_update (fs, installed, source_paragraph);
@@ -514,6 +514,20 @@ namespace vcpkg
514514 TrackedPackageInstallGuard& operator =(const TrackedPackageInstallGuard&) = delete ;
515515 };
516516
517+ void Install::preclear_packages (const VcpkgPaths& paths, const ActionPlan& action_plan)
518+ {
519+ auto & fs = paths.get_filesystem ();
520+ for (auto && action : action_plan.remove_actions )
521+ {
522+ fs.remove_all (paths.package_dir (action.spec ), VCPKG_LINE_INFO);
523+ }
524+
525+ for (auto && action : action_plan.install_actions )
526+ {
527+ fs.remove_all (action.package_dir .value_or_exit (VCPKG_LINE_INFO), VCPKG_LINE_INFO);
528+ }
529+ }
530+
517531 InstallSummary Install::execute_plan (const VcpkgCmdArguments& args,
518532 const ActionPlan& action_plan,
519533 const KeepGoing keep_going,
@@ -532,7 +546,6 @@ namespace vcpkg
532546 {
533547 TrackedPackageInstallGuard this_install (action_index++, action_count, results, action);
534548 Remove::remove_package (fs, paths.installed (), action.spec , status_db);
535- fs.remove_all (paths.packages () / action.spec .dir (), VCPKG_LINE_INFO);
536549 results.back ().build_result .emplace (BuildResult::REMOVED);
537550 }
538551
@@ -1270,6 +1283,7 @@ namespace vcpkg
12701283 paths.flush_lockfile ();
12711284
12721285 track_install_plan (action_plan);
1286+ Install::preclear_packages (paths, action_plan);
12731287
12741288 auto binary_cache = only_downloads ? BinaryCache (paths.get_filesystem ())
12751289 : BinaryCache::make (args, paths, stdout_sink).value_or_exit (VCPKG_LINE_INFO);
0 commit comments