local: mark repository files as read-only

This is intended to prevent accidental modifications of data files.
Marking the files as read-only was accidentally removed in #1258.
This commit is contained in:
Michael Eischer 2020-10-06 18:46:19 +02:00
parent 40ee17167e
commit f4282aa6fd
3 changed files with 5 additions and 4 deletions

View file

@ -130,9 +130,10 @@ func (b *Local) Save(ctx context.Context, h restic.Handle, rd restic.RewindReade
return errors.Wrap(err, "Close")
}
// try to mark file as read-only to avoid accidential modifications
// ignore if the operation fails as some filesystems don't allow the chmod call
// e.g. exfat and network file systems with certain mount options
err = setNewFileMode(filename, backend.Modes.File)
err = setFileReadonly(filename, backend.Modes.File)
if err != nil && !os.IsPermission(err) {
return errors.Wrap(err, "Chmod")
}