diff --git a/src/restic/backend/local/local.go b/src/restic/backend/local/local.go index 4af960e51..e09650e5c 100644 --- a/src/restic/backend/local/local.go +++ b/src/restic/backend/local/local.go @@ -157,11 +157,6 @@ func writeToTempfile(tempdir string, p []byte) (filename string, err error) { return "", errors.Wrap(err, "Syncn") } - err = fs.ClearCache(tmpfile) - if err != nil { - return "", errors.Wrap(err, "ClearCache") - } - err = tmpfile.Close() if err != nil { return "", errors.Wrap(err, "Close") diff --git a/src/restic/fs/file.go b/src/restic/fs/file.go index 2f6c500b2..b7e81a38b 100644 --- a/src/restic/fs/file.go +++ b/src/restic/fs/file.go @@ -125,6 +125,11 @@ func Create(name string) (*os.File, error) { return os.Create(fixpath(name)) } +// Open opens a file for reading. +func Open(name string) (File, error) { + return os.Open(fixpath(name)) +} + // OpenFile is the generalized open call; most users will use Open // or Create instead. It opens the named file with specified flag // (O_RDONLY etc.) and perm, (0666 etc.) if applicable. If successful, diff --git a/src/restic/fs/file_linux.go b/src/restic/fs/file_linux.go deleted file mode 100644 index f02c6470d..000000000 --- a/src/restic/fs/file_linux.go +++ /dev/null @@ -1,59 +0,0 @@ -// +build linux,go1.4 - -package fs - -import ( - "os" - "syscall" - - "restic/errors" - - "golang.org/x/sys/unix" -) - -// Open opens a file for reading, without updating the atime and without caching data on read. -func Open(name string) (File, error) { - file, err := os.OpenFile(name, os.O_RDONLY|syscall.O_NOATIME, 0) - if os.IsPermission(errors.Cause(err)) { - file, err = os.OpenFile(name, os.O_RDONLY, 0) - } - return &nonCachingFile{File: file}, err -} - -// nonCachingFile wraps an *os.File and calls fadvise() to instantly forget -// data that has been read or written. -type nonCachingFile struct { - *os.File - readOffset int64 -} - -func (f *nonCachingFile) Read(p []byte) (int, error) { - n, err := f.File.Read(p) - - if n > 0 { - ferr := unix.Fadvise(int(f.File.Fd()), f.readOffset, int64(n), unix.FADV_DONTNEED) - - f.readOffset += int64(n) - - if err == nil { - err = ferr - } - } - - return n, err -} - -// ClearCache syncs and then removes the file's content from the OS cache. -func ClearCache(file File) error { - f, ok := file.(*os.File) - if !ok { - panic("ClearCache called for file not *os.File") - } - - err := f.Sync() - if err != nil { - return err - } - - return unix.Fadvise(int(f.Fd()), 0, 0, unix.FADV_DONTNEED) -} diff --git a/src/restic/fs/file_nonlinux.go b/src/restic/fs/file_nonlinux.go deleted file mode 100644 index 672348074..000000000 --- a/src/restic/fs/file_nonlinux.go +++ /dev/null @@ -1,15 +0,0 @@ -// +build !linux !go1.4 - -package fs - -import "os" - -// Open opens a file for reading. -func Open(name string) (File, error) { - return os.OpenFile(fixpath(name), os.O_RDONLY, 0) -} - -// ClearCache syncs and then removes the file's content from the OS cache. -func ClearCache(f File) error { - return nil -}