From cd29a63ba7cd6516d5bbb7e51ea2c6c598ed3deb Mon Sep 17 00:00:00 2001 From: Kumar Harsh Date: Tue, 13 Mar 2018 17:40:03 +0530 Subject: [PATCH] Fix for "access is denied" errors on Windows - Using 'robocopy' instead of 'move' to copy files from tmp folder - robocopy is more robust and has support for long paths, thus providing better experience than xcopy with the same performance. --- path/winbug.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/path/winbug.go b/path/winbug.go index ddb423b4..8eef57f8 100644 --- a/path/winbug.go +++ b/path/winbug.go @@ -69,12 +69,13 @@ func CustomRemoveAll(p string) error { // at https://github.com/golang/go/issues/20841. func CustomRename(o, n string) error { - // Handking windows cases first + // Handling windows cases first if runtime.GOOS == "windows" { - msg.Debug("Detected Windows. Moving files using windows command") - cmd := exec.Command("cmd.exe", "/c", "move", o, n) + msg.Debug("Detected Windows. Moving files using windows command (robocopy)") + cmd := exec.Command("cmd.exe", "/c", "robocopy /s /move /nfl /ndl /njh /njs /nc /ns /np /r:1 /w:1", o, n) output, err := cmd.CombinedOutput() - if err != nil { + // robocopy exits with 1 for success. See https://ss64.com/nt/robocopy-exit.html + if err != nil && err.Error() != "exit status 1" { return fmt.Errorf("Error moving files: %s. output: %s", err, output) }