mirror of
https://github.com/restic/restic.git
synced 2026-06-21 16:14:18 +00:00
4d1b9cef63
Move TempFile and PreallocateFile into internal/fileio. internal/fs primarily focuses on converting between data.Node and the actual filesystem state. Extract the two methods to not pull in unnecessary dependencies.
35 lines
748 B
Go
35 lines
748 B
Go
//go:build !windows
|
|
|
|
package fs
|
|
|
|
import (
|
|
"os"
|
|
"syscall"
|
|
)
|
|
|
|
// fixpath returns an absolute path on windows, so restic can open long file
|
|
// names.
|
|
func fixpath(name string) string {
|
|
return name
|
|
}
|
|
|
|
// isNotSupported 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
|
|
}
|