mirror of
https://github.com/restic/restic.git
synced 2024-12-23 16:26:11 +00:00
Set file-mode in repository read-only (Closes #48)
This commit is contained in:
parent
248878022c
commit
23ac4f84dd
2 changed files with 28 additions and 6 deletions
|
@ -196,15 +196,26 @@ func (b *Local) tempFile() (*os.File, error) {
|
|||
|
||||
// Rename temp file to final name according to type and ID.
|
||||
func (b *Local) renameFile(file *os.File, t Type, id ID) error {
|
||||
newname := b.filename(t, id)
|
||||
filename := b.filename(t, id)
|
||||
oldname := file.Name()
|
||||
|
||||
if t == Data || t == Tree {
|
||||
// create directories if necessary, ignore errors
|
||||
os.MkdirAll(filepath.Dir(newname), dirMode)
|
||||
os.MkdirAll(filepath.Dir(filename), dirMode)
|
||||
}
|
||||
|
||||
return os.Rename(oldname, newname)
|
||||
err := os.Rename(oldname, filename)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// set mode to read-only
|
||||
fi, err := os.Stat(filename)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return os.Chmod(filename, fi.Mode()&os.FileMode(^uint32(0111)))
|
||||
}
|
||||
|
||||
// Construct directory for given Type.
|
||||
|
|
|
@ -302,17 +302,28 @@ func (r *SFTP) mkdirAll(dir string, mode os.FileMode) error {
|
|||
|
||||
// Rename temp file to final name according to type and ID.
|
||||
func (r *SFTP) renameFile(oldname string, t Type, id ID) error {
|
||||
newname := r.filename(t, id)
|
||||
filename := r.filename(t, id)
|
||||
|
||||
// create directories if necessary
|
||||
if t == Data || t == Tree {
|
||||
err := r.mkdirAll(filepath.Dir(newname), dirMode)
|
||||
err := r.mkdirAll(filepath.Dir(filename), dirMode)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return r.c.Rename(oldname, newname)
|
||||
err := r.c.Rename(oldname, filename)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// set mode to read-only
|
||||
fi, err := r.c.Lstat(filename)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return r.c.Chmod(filename, fi.Mode()&os.FileMode(^uint32(0111)))
|
||||
}
|
||||
|
||||
// Construct directory for given Type.
|
||||
|
|
Loading…
Reference in a new issue