mirror of
https://github.com/ScoopInstaller/Scoop.git
synced 2026-10-01 17:56:44 +00:00
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:
+22
-3
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user