diff options
author | Martin Pärtel <martin.partel@gmail.com> | 2014-05-10 12:37:38 +0100 |
---|---|---|
committer | Martin Pärtel <martin.partel@gmail.com> | 2014-05-10 12:37:38 +0100 |
commit | dc0cf937e50ea1abb7ce439a011531ddb3bbda02 (patch) | |
tree | 222fbf368ca78c6ef67787c0790280ae3614b385 /tests | |
parent | 60fc1f3f085983aa3fbb74102c270be8de15f9e5 (diff) | |
download | bindfs-dc0cf937e50ea1abb7ce439a011531ddb3bbda02.tar.gz |
Use lutimes() when utimensat() unavailable (#6).
Diffstat (limited to 'tests')
-rwxr-xr-x | tests/test_bindfs.rb | 25 | ||||
-rw-r--r-- | tests/utimens_nofollow.c | 35 |
2 files changed, 29 insertions, 31 deletions
diff --git a/tests/test_bindfs.rb b/tests/test_bindfs.rb index a1f1526..54521f0 100755 --- a/tests/test_bindfs.rb +++ b/tests/test_bindfs.rb @@ -370,22 +370,19 @@ root_testenv("", :title => "setgid directories") do assert { File.stat('mnt/dir/file').gid == $nogroup_gid } end -# utimensat() unavailable on OS X -unless RUBY_PLATFORM =~ /darwin/ - root_testenv("", :title => "utimens on symlinks") do - touch('mnt/file') - Dir.chdir "mnt" do - system('ln -sf file link') - end +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? + 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 + assert { File.lstat('mnt/link').atime.to_i < 50 } + 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. diff --git a/tests/utimens_nofollow.c b/tests/utimens_nofollow.c index 8316b26..02fcf58 100644 --- a/tests/utimens_nofollow.c +++ b/tests/utimens_nofollow.c @@ -1,45 +1,46 @@ -#ifndef __APPLE__ - -#define _BSD_SOURCE /* For atoll */ +#define _BSD_SOURCE /* For atoll and lutimes */ +#include <config.h> #include <stdlib.h> #include <stdio.h> #include <unistd.h> #include <sys/types.h> #include <sys/stat.h> +#include <sys/time.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; } +#ifdef HAVE_UTIMENSAT + struct timespec times[2]; 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; } +#elif HAVE_LUTIMES + struct timeval times[2]; + times[0].tv_sec = (time_t)atoll(argv[2]); + times[0].tv_usec = (suseconds_t)atoll(argv[3]) / 1000; + times[1].tv_sec = (time_t)atoll(argv[4]); + times[1].tv_usec = (suseconds_t)atoll(argv[5]) / 1000; + if (lutimes(argv[1], times) == -1) { + perror("failed to lutimes the given path"); + return 2; + } +#else +#error "No symlink-compatible utime* function available." +#endif return 0; } - -#else /* #ifndef __APPLE__ */ - -#include <stdio.h> -int main() -{ - fprintf("utimensat() unavailable on this platform\n"); - return 1; -} - -#endif /* #ifndef __APPLE__ */ |