2
2
mirror of https://github.com/octoleo/restic.git synced 2024-11-22 12:55:18 +00:00

Ignore error for Chmod() on FS that don't support it

See #1079
This commit is contained in:
Alexander Neumann 2017-07-18 21:47:30 +02:00
parent 6c05353086
commit 0abdcedcab
4 changed files with 27 additions and 12 deletions

View File

@ -5,15 +5,9 @@ package local
import (
"os"
"restic/fs"
"syscall"
)
// set file to readonly
func setNewFileMode(f string, fi os.FileInfo) error {
err := fs.Chmod(f, fi.Mode()&os.FileMode(^uint32(0222)))
// ignore the error if the FS does not support setting this mode (e.g. CIFS with gvfs on Linux)
if perr, ok := err.(*os.PathError); ok && perr.Err == syscall.ENOTSUP {
err = nil
}
return err
return fs.Chmod(f, fi.Mode()&os.FileMode(^uint32(0222)))
}

View File

@ -19,11 +19,6 @@ type File interface {
Stat() (os.FileInfo, error)
}
// Chmod changes the mode of the named file to mode.
func Chmod(name string, mode os.FileMode) error {
return os.Chmod(fixpath(name), mode)
}
// Mkdir creates a new directory with the specified name and permission bits.
// If there is an error, it will be of type *PathError.
func Mkdir(name string, perm os.FileMode) error {

View File

@ -5,6 +5,7 @@ package fs
import (
"io/ioutil"
"os"
"syscall"
)
// fixpath returns an absolute path on windows, so restic can open long file
@ -35,3 +36,23 @@ func TempFile(dir, prefix string) (f *os.File, err error) {
return f, nil
}
// isNotSuported returns true if the error is caused by an unsupported file system feature.
func isNotSupported(err error) bool {
if perr, ok := err.(*os.PathError); ok && perr.Err == syscall.ENOTSUP {
return true
}
return false
}
// Chmod changes the mode of the named file to mode.
func Chmod(name string, mode os.FileMode) error {
err := os.Chmod(fixpath(name), mode)
// ignore the error if the FS does not support setting this mode (e.g. CIFS with gvfs on Linux)
if err != nil && isNotSupported(err) {
return nil
}
return err
}

View File

@ -91,3 +91,8 @@ func MkdirAll(path string, perm os.FileMode) error {
func TempFile(dir, prefix string) (f *os.File, err error) {
return ioutil.TempFile(dir, prefix)
}
// Chmod changes the mode of the named file to mode.
func Chmod(name string, mode os.FileMode) error {
return os.Chmod(fixpath(name), mode)
}