From 9842eff887f779152ec220d1eccf8e847ae0c14d Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Thu, 20 Jul 2017 22:17:47 +0200 Subject: [PATCH] local/sftp: Remove unneeded stat() call --- internal/backend/local/local.go | 8 +------- internal/backend/local/local_unix.go | 4 ++-- internal/backend/local/local_windows.go | 2 +- internal/backend/sftp/sftp.go | 9 +-------- 4 files changed, 5 insertions(+), 18 deletions(-) diff --git a/internal/backend/local/local.go b/internal/backend/local/local.go index fd43332a8..e83d53d39 100644 --- a/internal/backend/local/local.go +++ b/internal/backend/local/local.go @@ -149,13 +149,7 @@ func (b *Local) Save(ctx context.Context, h restic.Handle, rd io.Reader) (err er return errors.Wrap(err, "Close") } - // set mode to read-only - fi, err := fs.Stat(filename) - if err != nil { - return errors.Wrap(err, "Stat") - } - - return setNewFileMode(filename, fi) + return setNewFileMode(filename, backend.Modes.File) } // Load returns a reader that yields the contents of the file at h at the diff --git a/internal/backend/local/local_unix.go b/internal/backend/local/local_unix.go index 5705960a2..74fb47bf4 100644 --- a/internal/backend/local/local_unix.go +++ b/internal/backend/local/local_unix.go @@ -9,6 +9,6 @@ import ( ) // set file to readonly -func setNewFileMode(f string, fi os.FileInfo) error { - return fs.Chmod(f, fi.Mode()&os.FileMode(^uint32(0222))) +func setNewFileMode(f string, mode os.FileMode) error { + return fs.Chmod(f, mode) } diff --git a/internal/backend/local/local_windows.go b/internal/backend/local/local_windows.go index 73633fa3e..be8f62d96 100644 --- a/internal/backend/local/local_windows.go +++ b/internal/backend/local/local_windows.go @@ -7,6 +7,6 @@ import ( // 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 { +func setNewFileMode(f string, mode os.FileMode) error { return nil } diff --git a/internal/backend/sftp/sftp.go b/internal/backend/sftp/sftp.go index 9961ac65c..0014f7549 100644 --- a/internal/backend/sftp/sftp.go +++ b/internal/backend/sftp/sftp.go @@ -348,14 +348,7 @@ func (r *SFTP) Save(ctx context.Context, h restic.Handle, rd io.Reader) (err err return errors.Wrap(err, "Close") } - // set mode to read-only - fi, err := r.c.Lstat(filename) - if err != nil { - return errors.Wrap(err, "Lstat") - } - - err = r.c.Chmod(filename, fi.Mode()&os.FileMode(^uint32(0222))) - return errors.Wrap(err, "Chmod") + return errors.Wrap(r.c.Chmod(filename, backend.Modes.File), "Chmod") } // Load returns a reader that yields the contents of the file at h at the