Fix robocopy not releasing a directory after moving it (closes #2305)

- Use System.Diagnostics.Process for better control
- Wait up to 1 second after moving a directory, so robocopy can terminate its threads
This commit is contained in:
Richard Kuhnt
2018-07-09 12:34:00 +02:00
parent 5fe75ddd24
commit e2792f2e02
+22 -3
View File
@@ -244,9 +244,28 @@ function movedir($from, $to) {
$from = $from.trimend('\')
$to = $to.trimend('\')
$out = robocopy "$from" "$to" /e /move
if($lastexitcode -ge 8) {
throw "Could not find '$(fname $from)'! (error $lastexitcode)"
$proc = New-Object System.Diagnostics.Process
$proc.StartInfo.FileName = 'robocopy.exe'
$proc.StartInfo.Arguments = "$from $to /e /move"
$proc.StartInfo.RedirectStandardOutput = $true
$proc.StartInfo.RedirectStandardError = $true
$proc.StartInfo.UseShellExecute = $false
$proc.StartInfo.WindowStyle = [System.Diagnostics.ProcessWindowStyle]::Hidden
$proc.Start()
$out = $proc.StandardOutput.ReadToEnd()
$proc.WaitForExit()
if($proc.ExitCode -ge 8) {
debug $out
throw "Could not find '$(fname $from)'! (error $($proc.ExitCode))"
}
# wait for robocopy to terminate its threads
1..10 | ForEach-Object {
if (!(Test-Path $from)) {
break
}
Start-Sleep -Milliseconds 100
}
}