diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Makefile.am | 3 | ||||
-rwxr-xr-x | tests/test_bindfs.rb | 15 | ||||
-rw-r--r-- | tests/utimens_nofollow.c | 32 |
3 files changed, 49 insertions, 1 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am index 2e053dd..8fc80ea 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1,6 +1,7 @@ -noinst_PROGRAMS = readdir_inode +noinst_PROGRAMS = readdir_inode utimens_nofollow readdir_inode_SOURCES = readdir_inode.c +utimens_nofollow_SOURCES = utimens_nofollow.c TESTS = test_bindfs.rb SUBDIRS = internals diff --git a/tests/test_bindfs.rb b/tests/test_bindfs.rb index f8a9d89..6e95020 100755 --- a/tests/test_bindfs.rb +++ b/tests/test_bindfs.rb @@ -371,6 +371,21 @@ root_testenv("", :title => "setgid directories") do assert { File.stat('mnt/dir/file').gid == $nogroup_gid } end +root_testenv("", :title => "utimens on symlinks") do + touch('mnt/file') + Dir.chdir "mnt" do + system('ln -sf file link') + end + + system("#{$tests_dir}/utimens_nofollow mnt/link 12 34 56 78") + raise "Failed to run utimens_nofollow: #{$?.inspect}" unless $?.success? + + assert { File.lstat('mnt/link').atime.to_i < 100 } + assert { File.lstat('mnt/link').mtime.to_i < 100 } + assert { File.lstat('mnt/file').atime.to_i > 100 } + assert { File.lstat('mnt/file').mtime.to_i > 100 } +end + # FIXME: this stuff around testenv is a hax, and testenv may also exit(), which defeats the 'ensure' below. # the test setup ought to be refactored. It might well use MiniTest or something. if Process.uid == 0 diff --git a/tests/utimens_nofollow.c b/tests/utimens_nofollow.c new file mode 100644 index 0000000..ced9b5f --- /dev/null +++ b/tests/utimens_nofollow.c @@ -0,0 +1,32 @@ + +#define _BSD_SOURCE /* For atoll */ + +#include <stdlib.h> +#include <stdio.h> +#include <unistd.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <errno.h> + +int main(int argc, char* argv[]) +{ + struct timespec times[2]; + + if (argc != 6) { + fprintf(stderr, "Usage: utimens_nofollow path atime atime_nsec mtime mtime_nsec\n"); + return 1; + } + + times[0].tv_sec = (time_t)atoll(argv[2]); + times[0].tv_nsec = atoll(argv[3]); + times[1].tv_sec = (time_t)atoll(argv[4]); + times[1].tv_nsec = atoll(argv[5]); + + if (utimensat(AT_FDCWD, argv[1], times, AT_SYMLINK_NOFOLLOW) == -1) { + perror("failed to utimensat the given path"); + return 2; + } + + return 0; +} |