local/sftp: Remove unneeded stat() call

This commit is contained in:
Alexander Neumann 2017-07-20 22:17:47 +02:00
parent c40b3d3983
commit 9842eff887
4 changed files with 5 additions and 18 deletions

View File

@ -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

View File

@ -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)
}

View File

@ -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
}

View File

@ -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