From 476977a7325ace1c84e74260bbdc5f8e4dd46194 Mon Sep 17 00:00:00 2001 From: sophia Date: Tue, 28 Jul 2020 09:52:59 -0500 Subject: [PATCH] Close and unlink iso tempfile On Windows tempfile.delete does not delete the file. It needs to be closed and unlinked --- lib/vagrant/util/caps.rb | 3 ++- test/unit/plugins/hosts/darwin/cap/fs_iso_test.rb | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/vagrant/util/caps.rb b/lib/vagrant/util/caps.rb index 4a7337d86..310add326 100644 --- a/lib/vagrant/util/caps.rb +++ b/lib/vagrant/util/caps.rb @@ -30,7 +30,8 @@ module Vagrant if file_destination.nil? tmpfile = Tempfile.new(["vagrant", ".iso"]) file_destination = Pathname.new(tmpfile.path) - tmpfile.delete + tmpfile.close + tmpfile.unlink else file_destination = Pathname.new(file_destination.to_s) # If the file destination path is a folder, target the output to a randomly named diff --git a/test/unit/plugins/hosts/darwin/cap/fs_iso_test.rb b/test/unit/plugins/hosts/darwin/cap/fs_iso_test.rb index f16bc1758..460fd33f8 100644 --- a/test/unit/plugins/hosts/darwin/cap/fs_iso_test.rb +++ b/test/unit/plugins/hosts/darwin/cap/fs_iso_test.rb @@ -62,7 +62,8 @@ describe VagrantPlugins::HostDarwin::Cap::FsISO do ).and_return(double(exit_code: 0)) # Should create a directory wherever Tempfile creates files by default expect(FileUtils).to receive(:mkdir_p).with(Pathname.new(file_destination).dirname) - + allow(file_destination).to receive(:close) + allow(file_destination).to receive(:unlink) output = subject.create_iso(env, "/foo/src") expect(output.to_s).to eq(file_destination) end