mirror of
https://github.com/octoleo/restic.git
synced 2024-11-16 18:15:20 +00:00
Merge pull request #1112 from restic/fix-chmod-not-supported
Ignore error for Chmod() on FS that don't support it
This commit is contained in:
commit
2f00287e45
@ -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)))
|
||||
}
|
||||
|
@ -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 {
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user