lib/osutil: Don't remove before rename on Windows (ref #6493) (#6495)

This was needed in ancient times but not currently.
This commit is contained in:
Jakob Borg
2020-04-04 14:17:16 +02:00
committed by GitHub
parent e1324a0e23
commit 7505ea79a0
2 changed files with 10 additions and 12 deletions
-11
View File
@@ -9,7 +9,6 @@ package osutil
import (
"errors"
"path/filepath"
"runtime"
"github.com/syncthing/syncthing/lib/fs"
)
@@ -93,16 +92,6 @@ func (w *AtomicWriter) Close() error {
return err
}
// Remove the destination file, on Windows only. If it fails, and not due
// to the file not existing, we won't be able to complete the rename
// either. Return this error because it may be more informative. On non-
// Windows we want the atomic rename behavior so we don't attempt remove.
if runtime.GOOS == "windows" {
if err := w.fs.Remove(w.path); err != nil && !fs.IsNotExist(err) {
return err
}
}
if err := w.fs.Rename(w.next.Name(), w.path); err != nil {
w.err = err
return err