File: file_unix.go

package info (click to toggle)
continuity 0.0~git20180216.d8fb858-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 620 kB
  • sloc: makefile: 46; sh: 28; asm: 3
file content (29 lines) | stat: -rw-r--r-- 766 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// +build !windows

package fstest

import (
	"path/filepath"
	"time"

	"github.com/containerd/continuity/sysx"
	"golang.org/x/sys/unix"
)

// SetXAttr sets the xatter for the file
func SetXAttr(name, key, value string) Applier {
	return applyFn(func(root string) error {
		return sysx.LSetxattr(name, key, []byte(value), 0)
	})
}

// Lchtimes changes access and mod time of file without following symlink
func Lchtimes(name string, atime, mtime time.Time) Applier {
	return applyFn(func(root string) error {
		path := filepath.Join(root, name)
		at := unix.NsecToTimespec(atime.UnixNano())
		mt := unix.NsecToTimespec(mtime.UnixNano())
		utimes := [2]unix.Timespec{at, mt}
		return unix.UtimesNanoAt(unix.AT_FDCWD, path, utimes[0:], unix.AT_SYMLINK_NOFOLLOW)
	})
}