Fixed ignored files still get copied

This commit is contained in:
Zhongcheng Lao 2019-06-19 20:55:55 +08:00
parent a93e1215b3
commit 524c24fe94
3 changed files with 25 additions and 29 deletions

View File

@ -237,14 +237,14 @@ module VagrantPlugins
fn = File.join(windows_temp, ".hv_sync_files_#{suffix}")
begin
File.open(fn, 'w') do |file|
file.write dirs.to_json
file.write files.to_json
end
win_path = Vagrant::Util::Platform.format_windows_path(
fn, :disable_unc)
status = execute(:sync_files,
vm_id: vm_id,
guest_ip: guest_ip,
dir_list: win_path)
file_list: win_path)
status
ensure
FileUtils.rm_f(fn)

View File

@ -10,29 +10,25 @@ param (
[parameter (Mandatory=$true)]
[string]$guest_ip,
[parameter (Mandatory=$true)]
[string]$dir_list,
[string]$file_list,
[string]$path_separator
)
function copy-file($machine, $dir_list, $path_separator) {
$files = Get-Content $dir_list | ConvertFrom-Json
function copy-file($machine, $file_list, $path_separator) {
$files = Get-Content $file_list | ConvertFrom-Json
$succeeded = @()
$failed = @()
foreach ($line in $files.PSObject.Properties) {
$sourceDir = $line.Name
$destDir = $line.Value
Get-ChildItem $sourceDir -File | ForEach-Object -Process {
$from = $sourceDir + "\" + $_.Name
$to = $destDir
Write-Host "Copying $from to $($machine) => $to..."
Try {
Hyper-V\Copy-VMFile -VM $machine -SourcePath $from -DestinationPath $to -CreateFullPath -FileSource Host -Force
$succeeded += $from
Write-Host "Copied $from to $($machine) => $to."
} Catch {
$failed += $from
Break
}
$from = $sourceDir = $line.Name
$to = $destDir = $line.Value
Write-Host "Copying $from to $($machine) => $to..."
Try {
Hyper-V\Copy-VMFile -VM $machine -SourcePath $from -DestinationPath $to -CreateFullPath -FileSource Host -Force
$succeeded += $from
Write-Host "Copied $from to $($machine) => $to."
} Catch {
$failed += $from
Break
}
}
[hashtable]$return = @{}
@ -43,7 +39,7 @@ function copy-file($machine, $dir_list, $path_separator) {
$machine = Hyper-V\Get-VM -Id $vm_id
$status = copy-file $machine $dir_list $path_separator
$status = copy-file $machine $file_list $path_separator
$resultHash = @{
message = "OK"

View File

@ -130,7 +130,7 @@ describe VagrantPlugins::HyperV::Driver do
let(:windows_path) { "WIN_PATH" }
let(:windows_temp) { "TEMP_DIR" }
let(:wsl_temp) { "WSL_TEMP" }
let(:dir_list) { double("file") }
let(:file_list) { double("file") }
before do
allow(subject).to receive(:read_guest_ip).and_return(guest_ip)
@ -138,17 +138,17 @@ describe VagrantPlugins::HyperV::Driver do
allow(Vagrant::Util::Subprocess).to receive(:execute).
with("wslpath", "-u", "-a", windows_temp).and_return(double(exit_code: 0, stdout: wsl_temp))
allow(File).to receive(:open) do |fn, type, &proc|
proc.call dir_list
proc.call file_list
allow(Vagrant::Util::Platform).to receive(:format_windows_path).
with(fn, :disable_unc).and_return(windows_path)
allow(FileUtils).to receive(:rm_f).with(fn)
end.and_return(dir_list)
allow(dir_list).to receive(:write).with(dirs.to_json)
end.and_return(file_list)
allow(file_list).to receive(:write).with(files.to_json)
allow(subject).to receive(:execute).with(:sync_files,
vm_id: vm_id,
guest_ip: guest_ip["ip"],
dir_list: windows_path)
file_list: windows_path)
end
after { subject.sync_files vm_id, dirs, files, is_win_guest: false }
@ -182,20 +182,20 @@ describe VagrantPlugins::HyperV::Driver do
expect(fn).to match(/#{temp_dir}\/\.hv_sync_files_.*/)
expect(type).to eq('w')
proc.call dir_list
proc.call file_list
expect(Vagrant::Util::Platform).to receive(:format_windows_path).
with(fn, :disable_unc).and_return(windows_path)
expect(FileUtils).to receive(:rm_f).with(fn)
end.and_return(dir_list)
expect(dir_list).to receive(:write).with(dirs.to_json)
end.and_return(file_list)
expect(file_list).to receive(:write).with(files.to_json)
end
it "calls sync files powershell script" do
expect(subject).to receive(:execute).with(:sync_files,
vm_id: vm_id,
guest_ip: guest_ip["ip"],
dir_list: windows_path)
file_list: windows_path)
end
end
end