summaryrefslogtreecommitdiff
path: root/test-suite/tests
diff options
context:
space:
mode:
authorMaxime Devos <maximedevos@telenet.be>2021-11-16 11:06:32 +0000
committerLudovic Courtès <ludo@gnu.org>2022-10-21 17:40:37 +0200
commit19b48b1c4a0335851a51d1ac69a24b154d401fdd (patch)
tree41be50b4b85a9305399d2347f1b9efa950eb4790 /test-suite/tests
parent3a0554c60fb12857c67d2eb0bd04cf8c59014f55 (diff)
downloadguile-19b48b1c4a0335851a51d1ac69a24b154d401fdd.tar.gz
Define a Scheme binding to ‘fchmodat’ when it exists.
* configure.ac: Detect existence of fchmodat. * libguile/filesys.c (scm_chmodat): New procedure. * libguile/filesys.h (scm_chmodat): Make it part of the API. * test-suite/tests/filesys.test ("chmodat"): Test it. Signed-off-by: Ludovic Courtès <ludo@gnu.org>
Diffstat (limited to 'test-suite/tests')
-rw-r--r--test-suite/tests/filesys.test53
1 files changed, 53 insertions, 0 deletions
diff --git a/test-suite/tests/filesys.test b/test-suite/tests/filesys.test
index bbce2c858..204f3414c 100644
--- a/test-suite/tests/filesys.test
+++ b/test-suite/tests/filesys.test
@@ -271,6 +271,59 @@
(false-if-exception (rmdir name))
result)))))
+;;;
+;;; chmodat
+;;;
+
+(with-test-prefix "chmodat"
+ (call-with-output-file (test-file) (const #f))
+ (chmod (test-file) #o000)
+
+ (pass-if-equal "regular file"
+ #o300
+ (unless (defined? 'chmodat)
+ (throw 'unsupported))
+ (call-with-port
+ (open (dirname (test-file)) O_RDONLY)
+ (lambda (port)
+ (chmodat port (test-file) #o300)))
+ (stat:perms (stat (test-file))))
+
+ (chmod (test-file) #o000)
+
+ (pass-if-equal "regular file, AT_SYMLINK_NOFOLLOW"
+ #o300
+ (unless (and (defined? 'chmodat)
+ (defined? 'AT_SYMLINK_NOFOLLOW))
+ (throw 'unsupported))
+ (call-with-port
+ (open (dirname (test-file)) O_RDONLY)
+ (lambda (port)
+ (catch 'system-error
+ (lambda ()
+ (chmodat port (basename (test-file)) #o300 AT_SYMLINK_NOFOLLOW))
+ (lambda args
+ (close-port port)
+ ;; AT_SYMLINK_NOFOLLOW is not supported on Linux (at least Linux
+ ;; 5.11.2 with the btrfs file system), even for regular files.
+ (if (= ENOTSUP (system-error-errno args))
+ (begin
+ (display "fchmodat doesn't support AT_SYMLINK_NOFOLLOW\n")
+ (throw 'unresolved))
+ (apply throw args))))))
+ (stat:perms (stat (test-file))))
+
+ (pass-if-exception "not a port" exception:wrong-type-arg
+ (chmodat "bogus" (test-file) #o300))
+
+ (pass-if-exception "not a file port" exception:wrong-type-arg
+ (chmodat (open-input-string "") (test-file) #o300))
+
+ (pass-if-exception "closed port" exception:wrong-type-arg
+ (chmodat (call-with-port (open "." O_RDONLY) identity) (test-file) #o300))
+
+ (delete-file (test-file)))
+
(with-test-prefix "chdir"
(pass-if-equal "current directory" (getcwd)
(begin (chdir ".") (getcwd)))