]> Savannah Git Hosting - gnulib.git/commitdiff
utimens: Fix test failure on macOS 10.13.
authorBruno Haible <bruno@clisp.org>
Sat, 2 Jan 2021 17:59:12 +0000 (18:59 +0100)
committerBruno Haible <bruno@clisp.org>
Sat, 2 Jan 2021 17:59:12 +0000 (18:59 +0100)
* lib/utimens.c (fdutimens): Before calling utimensat, recognize a
filename ending in a slash that does not point to a directory.

ChangeLog
lib/utimens.c

index 73d11397b2dddad35dea907ae1d508b690709629..5087bf4e62c2d2c19366c7ea888c176efb12ef37 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2021-01-02  Bruno Haible  <bruno@clisp.org>
+
+       utimens: Fix test failure on macOS 10.13.
+       * lib/utimens.c (fdutimens): Before calling utimensat, recognize a
+       filename ending in a slash that does not point to a directory.
+
 2021-01-02  Bruno Haible  <bruno@clisp.org>
 
        utimens: Avoid test failures on macOS 10.13.
index 5bbae0581325584ffef922bf2c303e8ef862138f..9f9c30af2fdea7ddc399b670ddb9d8aacfcbc03b 100644 (file)
@@ -246,6 +246,20 @@ fdutimens (int fd, char const *file, struct timespec const timespec[2])
 # if HAVE_UTIMENSAT
       if (fd < 0)
         {
+#  if defined __APPLE__ && defined __MACH__
+          size_t len = strlen (file);
+          if (len > 0 && file[len - 1] == '/')
+            {
+              struct stat statbuf;
+              if (stat (file, &statbuf) < 0)
+                return -1;
+              if (!S_ISDIR (statbuf.st_mode))
+                {
+                  errno = ENOTDIR;
+                  return -1;
+                }
+            }
+#  endif
           result = utimensat (AT_FDCWD, file, ts, 0);
 #  ifdef __linux__
           /* Work around a kernel bug: