1// +build !windows 2 3package fs 4 5import ( 6 "io/ioutil" 7 "os" 8 "syscall" 9) 10 11// fixpath returns an absolute path on windows, so restic can open long file 12// names. 13func fixpath(name string) string { 14 return name 15} 16 17// TempFile creates a temporary file which has already been deleted (on 18// supported platforms) 19func TempFile(dir, prefix string) (f *os.File, err error) { 20 f, err = ioutil.TempFile(dir, prefix) 21 if err != nil { 22 return nil, err 23 } 24 25 if err = os.Remove(f.Name()); err != nil { 26 return nil, err 27 } 28 29 return f, nil 30} 31 32// isNotSuported returns true if the error is caused by an unsupported file system feature. 33func isNotSupported(err error) bool { 34 if perr, ok := err.(*os.PathError); ok && perr.Err == syscall.ENOTSUP { 35 return true 36 } 37 return false 38} 39 40// Chmod changes the mode of the named file to mode. 41func Chmod(name string, mode os.FileMode) error { 42 err := os.Chmod(fixpath(name), mode) 43 44 // ignore the error if the FS does not support setting this mode (e.g. CIFS with gvfs on Linux) 45 if err != nil && isNotSupported(err) { 46 return nil 47 } 48 49 return err 50} 51