var oldStat fs.FileInfo
reopen:
- oldFh, err := os.OpenFile(file.Path,
- // O_NOFOLLOW prevents symlink attacks
- // O_NONBLOCK is necessary to prevent blocking on FIFOs
- os.O_RDONLY|syscall.O_NOFOLLOW|syscall.O_NONBLOCK, 0)
+ oldFh, err := OpenFileNoFollow(file.Path)
if err != nil {
err := err.(*fs.PathError)
if err.Err == syscall.ELOOP {
// a symlink at this point. There's no lchmod so open the
// directory.
debugf("chmodding %s", file.Mode)
- dh, err := os.OpenFile(file.Path,
- os.O_RDONLY|syscall.O_NOFOLLOW|syscall.O_NONBLOCK, 0)
+ dh, err := OpenFileNoFollow(file.Path)
if err != nil {
return err
}
return result, nil
}
+func OpenFileNoFollow(path string) (*os.File, error) {
+ return os.OpenFile(path,
+ // O_NOFOLLOW prevents symlink attacks
+ // O_NONBLOCK is necessary to prevent blocking on FIFOs
+ os.O_RDONLY|syscall.O_NOFOLLOW|syscall.O_NONBLOCK, 0)
+}
+
// syncPath syncs path, which should be a directory. To guarantee durability
// it must be called on a parent directory after adding, renaming or removing
// files therein.