File: syscall_test.go

package info (click to toggle)
golang-github-hanwen-go-fuse 2.1.0%2Bgit20220822.58a7e14-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,292 kB
  • sloc: cpp: 78; sh: 43; makefile: 16
file content (49 lines) | stat: -rw-r--r-- 927 bytes parent folder | download | duplicates (4)
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Copyright 2016 the Go-FUSE Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// +build linux

package pathfs

import (
	"os"
	"reflect"
	"syscall"
	"testing"
)

func TestSysUtimensat(t *testing.T) {
	symlink := "/tmp/TestSysUtimensat"
	os.Remove(symlink)
	err := os.Symlink("/nonexisting/file", symlink)
	if err != nil {
		t.Fatal(err)
	}

	var ts [2]syscall.Timespec
	// Atime
	ts[0].Nsec = 1111
	ts[0].Sec = 2222
	// Mtime
	ts[1].Nsec = 3333
	ts[1].Sec = 4444

	// Linux specific.
	err = sysUtimensat(0, symlink, &ts, _AT_SYMLINK_NOFOLLOW)
	if err != nil {
		t.Fatal(err)
	}

	var st syscall.Stat_t
	err = syscall.Lstat(symlink, &st)
	if err != nil {
		t.Fatal(err)
	}
	if !reflect.DeepEqual(st.Atim, ts[0]) {
		t.Errorf("Wrong atime: %v", st.Atim)
	}
	if !reflect.DeepEqual(st.Mtim, ts[1]) {
		t.Errorf("Wrong mtime: %v", st.Mtim)
	}
}