From 8f1e51789dd29b9fae82a059e2890bf9873cdd4c Mon Sep 17 00:00:00 2001 From: Jakob Unterwurzacher Date: Sun, 25 Sep 2016 16:17:26 +0200 Subject: [PATCH] tests: set the times on a symlink This currently fails as reported in https://github.com/rfjakob/gocryptfs/issues/35 . Also remove the spurious sleep in the test. --- tests/matrix/matrix_test.go | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/tests/matrix/matrix_test.go b/tests/matrix/matrix_test.go index 853fb0e..ebca867 100644 --- a/tests/matrix/matrix_test.go +++ b/tests/matrix/matrix_test.go @@ -16,11 +16,11 @@ import ( "fmt" "io/ioutil" "os" + "os/exec" "runtime" "sync" "syscall" "testing" - "time" "github.com/rfjakob/gocryptfs/internal/syscallcompat" "github.com/rfjakob/gocryptfs/tests/test_helpers" @@ -571,7 +571,7 @@ func TestLchown(t *testing.T) { } } -// Set nanoseconds by path +// Set nanoseconds by path, normal file func TestUtimesNano(t *testing.T) { path := test_helpers.DefaultPlainDir + "/utimesnano" err := ioutil.WriteFile(path, []byte("foobar"), 0600) @@ -589,7 +589,6 @@ func TestUtimesNano(t *testing.T) { if err != nil { t.Fatal(err) } - time.Sleep(1 * time.Second) var st syscall.Stat_t err = syscall.Stat(path, &st) if err != nil { @@ -603,6 +602,24 @@ func TestUtimesNano(t *testing.T) { } } +// Set nanoseconds by path, symlink +func TestUtimesNanoSymlink(t *testing.T) { + path := test_helpers.DefaultPlainDir + "/utimesnano_symlink" + err := os.Symlink("/some/nonexisting/file", path) + if err != nil { + t.Fatal(err) + } + // syscall.UtimesNano does not provide a way to pass AT_SYMLINK_NOFOLLOW, + // so we call the external utility "touch", which does. + cmd := exec.Command("touch", "--no-dereference", path) + cmd.Stderr = os.Stderr + cmd.Stdout = os.Stdout + err = cmd.Run() + if err != nil { + t.Error(err) + } +} + // Set nanoseconds by fd func TestUtimesNanoFd(t *testing.T) { path := test_helpers.DefaultPlainDir + "/utimesnanofd"