File: setflags_linux.go

package info (click to toggle)
restic 0.18.1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 30,824 kB
  • sloc: sh: 3,704; makefile: 50; python: 34
file content (21 lines) | stat: -rw-r--r-- 514 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
package fs

import (
	"os"

	"golang.org/x/sys/unix"
)

// SetFlags tries to set the O_NOATIME flag on f, which prevents the kernel
// from updating the atime on a read call.
//
// The call fails when we're not the owner of the file or root. The caller
// should ignore the error, which is returned for testing only.
func setFlags(f *os.File) error {
	fd := f.Fd()
	flags, err := unix.FcntlInt(fd, unix.F_GETFL, 0)
	if err == nil {
		_, err = unix.FcntlInt(fd, unix.F_SETFL, flags|unix.O_NOATIME)
	}
	return err
}