diff options
author | Eric Blake <ebb9@byu.net> | 2009-10-15 12:04:57 -0600 |
---|---|---|
committer | Eric Blake <ebb9@byu.net> | 2009-10-16 08:26:12 -0600 |
commit | 0c278290674f9bb9749d27f2885da510a78acc79 (patch) | |
tree | f2e2316206343801f0485ac8268b9b05148f51e7 /tests/test-lutimens.h | |
parent | c1572a883111051641846698f7b5a7e590206c5d (diff) | |
download | gnulib-0c278290674f9bb9749d27f2885da510a78acc79.tar.gz |
utimens: let lutimens work on non-symlinks
Coreutils new 'touch -h' is easier to write if we guarantee POSIX
semantics of utimensat(fd,"file",NULL,AT_SYMLINK_NOFOLLOW), rather
than blindly failing with ENOSYS even on non-symlinks.
* lib/utimens.c (lutimens): Fall back to utimens rather than
failing with ENOSYS, when file is not a symlink.
(utimens): Reduce redirection.
* tests/test-lutimens.h (test_lutimens): Update test to cover
non-symlinks.
* tests/test-utimens.h (test_utimens): Update test to cover
symlinks.
* tests/test-utimens.c (main): Update caller.
Signed-off-by: Eric Blake <ebb9@byu.net>
Diffstat (limited to 'tests/test-lutimens.h')
-rw-r--r-- | tests/test-lutimens.h | 41 |
1 files changed, 33 insertions, 8 deletions
diff --git a/tests/test-lutimens.h b/tests/test-lutimens.h index 632b103c1e..67658325cf 100644 --- a/tests/test-lutimens.h +++ b/tests/test-lutimens.h @@ -24,12 +24,34 @@ static int test_lutimens (int (*func) (char const *, struct timespec const *), bool print) { int result; + int saved_errno; struct stat st1; struct stat st2; bool atime_supported = true; - if (symlink ("nowhere", BASE "link")) + /* Non-symlinks should be handled just like utimens. */ + errno = 0; + ASSERT (func ("no_such", NULL) == -1); + ASSERT (errno == ENOENT); + errno = 0; + ASSERT (func ("", NULL) == -1); + ASSERT (errno == ENOENT); + ASSERT (close (creat (BASE "file", 0600)) == 0); + ASSERT (stat (BASE "file", &st1) == 0); + ASSERT (st1.st_atime != Y2K); + ASSERT (st1.st_mtime != Y2K); + { + struct timespec ts[2] = { { Y2K, 0 }, { Y2K, 0 } }; + ASSERT (func (BASE "file", ts) == 0); + } + ASSERT (stat (BASE "file", &st1) == 0); + ASSERT (st1.st_atime == Y2K); + ASSERT (st1.st_mtime == Y2K); + + /* Play with symlink timestamps. */ + if (symlink (BASE "file", BASE "link")) { + ASSERT (unlink (BASE "file") == 0); if (print) fputs ("skipping test: symlinks not supported on this file system\n", stderr); @@ -37,7 +59,16 @@ test_lutimens (int (*func) (char const *, struct timespec const *), bool print) } errno = 0; result = func (BASE "link", NULL); - if (result == -1 && errno == ENOSYS) + saved_errno = errno; + /* Make sure we did not reference through link by accident. */ + ASSERT (stat (BASE "file", &st1) == 0); + ASSERT (st1.st_atime == Y2K); + ASSERT (st1.st_mtime == Y2K); + ASSERT (lstat (BASE "link", &st1) == 0); + ASSERT (st1.st_atime != Y2K); + ASSERT (st1.st_mtime != Y2K); + ASSERT (unlink (BASE "file") == 0); + if (result == -1 && saved_errno == ENOSYS) { ASSERT (unlink (BASE "link") == 0); if (print) @@ -57,12 +88,6 @@ test_lutimens (int (*func) (char const *, struct timespec const *), bool print) atime_supported = false; /* Invalid arguments. */ - errno = 0; - ASSERT (func ("no_such", NULL) == -1); - ASSERT (errno == ENOENT); - errno = 0; - ASSERT (func ("", NULL) == -1); - ASSERT (errno == ENOENT); { struct timespec ts[2] = { { Y2K, UTIME_BOGUS_POS }, { Y2K, 0 } }; errno = 0; |