diff --git a/backend/local/local.go b/backend/local/local.go index f63a71743..6f5d9d976 100644 --- a/backend/local/local.go +++ b/backend/local/local.go @@ -7,7 +7,6 @@ import ( "io/ioutil" "os" "path/filepath" - "runtime" "sort" "sync" @@ -147,16 +146,7 @@ func (lb *localBlob) Finalize(t backend.Type, name string) error { return err } - // set file to readonly, except on Windows, - // otherwise deletion will fail. - if runtime.GOOS != "windows" { - err = os.Chmod(f, fi.Mode()&os.FileMode(^uint32(0222))) - if err != nil { - return err - } - } - - return nil + return setNewFileMode(f, fi) } // Create creates a new Blob. The data is available only after Finalize() diff --git a/backend/local/local_unix.go b/backend/local/local_unix.go new file mode 100644 index 000000000..8b8ecec69 --- /dev/null +++ b/backend/local/local_unix.go @@ -0,0 +1,12 @@ +// +build !windows + +package local + +import ( + "os" +) + +// set file to readonly +func setNewFileMode(f string, fi os.FileInfo) error { + return os.Chmod(f, fi.Mode()&os.FileMode(^uint32(0222))) +} diff --git a/backend/local/local_windows.go b/backend/local/local_windows.go new file mode 100644 index 000000000..73633fa3e --- /dev/null +++ b/backend/local/local_windows.go @@ -0,0 +1,12 @@ +package local + +import ( + "os" +) + +// We don't modify read-only on windows, +// since it will make us unable to delete the file, +// and this isn't common practice on this platform. +func setNewFileMode(f string, fi os.FileInfo) error { + return nil +}