mirror of
https://github.com/octoleo/syncthing.git
synced 2024-11-08 22:31:04 +00:00
This was needed in ancient times but not currently.
This commit is contained in:
parent
e1324a0e23
commit
7505ea79a0
@ -9,7 +9,6 @@ package osutil
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
|
||||||
|
|
||||||
"github.com/syncthing/syncthing/lib/fs"
|
"github.com/syncthing/syncthing/lib/fs"
|
||||||
)
|
)
|
||||||
@ -93,16 +92,6 @@ func (w *AtomicWriter) Close() error {
|
|||||||
return err
|
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 {
|
if err := w.fs.Rename(w.next.Name(), w.path); err != nil {
|
||||||
w.err = err
|
w.err = err
|
||||||
return err
|
return err
|
||||||
|
@ -52,6 +52,15 @@ func TestCreateAtomicCreate(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestCreateAtomicReplace(t *testing.T) {
|
func TestCreateAtomicReplace(t *testing.T) {
|
||||||
|
testCreateAtomicReplace(t, 0644)
|
||||||
|
}
|
||||||
|
func TestCreateAtomicReplaceReadOnly(t *testing.T) {
|
||||||
|
testCreateAtomicReplace(t, 0400)
|
||||||
|
}
|
||||||
|
|
||||||
|
func testCreateAtomicReplace(t *testing.T, oldPerms os.FileMode) {
|
||||||
|
t.Helper()
|
||||||
|
|
||||||
os.RemoveAll("testdata")
|
os.RemoveAll("testdata")
|
||||||
defer os.RemoveAll("testdata")
|
defer os.RemoveAll("testdata")
|
||||||
|
|
||||||
@ -59,7 +68,7 @@ func TestCreateAtomicReplace(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := ioutil.WriteFile("testdata/file", []byte("some old data"), 0644); err != nil {
|
if err := ioutil.WriteFile("testdata/file", []byte("some old data"), oldPerms); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user