]> Savannah Git Hosting - gnulib.git/commitdiff
utime: Fix a test failure on macOS 10.13.
authorBruno Haible <bruno@clisp.org>
Fri, 4 Dec 2020 23:17:02 +0000 (00:17 +0100)
committerBruno Haible <bruno@clisp.org>
Fri, 4 Dec 2020 23:22:49 +0000 (00:22 +0100)
Reported by Martin Storsjö <martin@martin.st> in
<https://lists.gnu.org/archive/html/bug-gnulib/2020-12/msg00003.html>.

* m4/utime.m4 (gl_FUNC_UTIME): Test whether utime handles trailing
slashes on files.
* lib/utime.c (utime): Add alternative implementation for Unix
platforms.
* modules/utime (Depends-on): Add stat.
* doc/posix-functions/utime.texi: Mention the macOS 10.13 bug.
* doc/posix-functions/lstat.texi: Mention that macOS 10.13 also has the
trailing-slash bug.
* doc/posix-functions/open.texi: Likewise.
* doc/posix-functions/stat.texi: Likewise.
* doc/posix-functions/symlink.texi: Likewise.

ChangeLog
doc/posix-functions/lstat.texi
doc/posix-functions/open.texi
doc/posix-functions/stat.texi
doc/posix-functions/symlink.texi
doc/posix-functions/utime.texi
lib/utime.c
m4/utime.m4
modules/utime

index 5c19598b411c1469f59e7271a388079e9a4d0660..3de636895915cb17806b62ac792496ecdb34e839 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,20 @@
+2020-12-04  Bruno Haible  <bruno@clisp.org>
+
+       utime: Fix a test failure on macOS 10.13.
+       Reported by Martin Storsjö <martin@martin.st> in
+       <https://lists.gnu.org/archive/html/bug-gnulib/2020-12/msg00003.html>.
+       * m4/utime.m4 (gl_FUNC_UTIME): Test whether utime handles trailing
+       slashes on files.
+       * lib/utime.c (utime): Add alternative implementation for Unix
+       platforms.
+       * modules/utime (Depends-on): Add stat.
+       * doc/posix-functions/utime.texi: Mention the macOS 10.13 bug.
+       * doc/posix-functions/lstat.texi: Mention that macOS 10.13 also has the
+       trailing-slash bug.
+       * doc/posix-functions/open.texi: Likewise.
+       * doc/posix-functions/stat.texi: Likewise.
+       * doc/posix-functions/symlink.texi: Likewise.
+
 2020-12-04  Paul Eggert  <eggert@cs.ucla.edu>
 
        intprops: update doc and mention Unisys
index 1b1aff62cd370bfc3fe8e669f491408045caa5b8..1a1ffb448e04ea1674c7c8d653590aa5ba5096a1 100644 (file)
@@ -24,7 +24,7 @@ Solaris 9.
 @item
 On some platforms, @code{lstat("file/",buf)} succeeds instead of
 failing with @code{ENOTDIR}.
-Solaris 9.
+Mac OS X 10.13, Solaris 9.
 @item
 On Solaris 11.4, when this function yields a timestamp with a
 nonpositive @code{tv_sec} value, @code{tv_nsec} might be in the range
index d4767d9c7bcc9d51151bcbf56cefcbd20307f726..7e4f1874eec9b1753618d7347e47ad7bd8f31faa 100644 (file)
@@ -19,7 +19,7 @@ correctly with files larger than 2 GB@.  (Cf. @code{AC_SYS_LARGEFILE}.)
 This function does not fail when the file name argument ends in a slash
 and (without the slash) names a nonexistent file or a file that is not a
 directory, on some platforms:
-FreeBSD 7.2, AIX 7.1, HP-UX 11.00, Solaris 9.
+Mac OS X 10.13, FreeBSD 7.2, AIX 7.1, HP-UX 11.00, Solaris 9.
 @item
 This function does not support the @code{O_NONBLOCK} flag when it is defined
 by the gnulib module @code{nonblocking} on some platforms:
index 27fbe278b3f46e2535bffec39f29c5f07a36efb7..1d1f9276446f727a7d0a0fbab7adaeaa40ca5730 100644 (file)
@@ -29,7 +29,7 @@ on directories such as @samp{C:\System Volume Information}.
 @item
 On some platforms, @code{stat("link-to-file/",buf)} succeeds instead
 of failing with @code{ENOTDIR}.
-FreeBSD 7.2, AIX 7.1, Solaris 9, mingw64.
+Mac OS X 10.13, FreeBSD 7.2, AIX 7.1, Solaris 9, mingw64.
 @item
 On some platforms, @code{stat(".",buf)} and @code{stat("./",buf)} give
 different results:
index 88d1c772f015fa4a9a4ef4eb3cae1976ed7dfa32..3826ccfb817ed303e928da0a684ab1ce4c245da1 100644 (file)
@@ -11,7 +11,7 @@ Portability problems fixed by Gnulib:
 @item
 On some systems, @code{symlink(value,"name/")} mistakenly creates a
 symlink:
-FreeBSD 7.2, AIX 7.1, Solaris 9.
+Mac OS X 10.13, FreeBSD 7.2, AIX 7.1, Solaris 9.
 @item
 This function is missing on some platforms; however, the replacement
 always fails with @code{EPERM}:
index d019c4a8ac1bc9012e63eb0ddd9e92a85dcf62e0..4e41e5d52c5b4dbfa40e85e362700679699c55c5 100644 (file)
@@ -16,6 +16,10 @@ mingw, MSVC 14 (when the environment variable @code{TZ} is set).
 On some platforms, the prototype for @code{utime} omits @code{const}
 for the second argument:
 mingw, MSVC 14.
+@item
+On some platforms, @code{utime("link-to-file/",buf)} succeeds instead
+of failing with @code{ENOTDIR}.
+Mac OS X 10.13.
 @end itemize
 
 Portability problems not fixed by Gnulib:
index c35eb169e6b228b572ecb1744b31303a7781efac..f6465a3cf1f1cd85520909d4a684b34573983ed3 100644 (file)
@@ -259,4 +259,29 @@ utime (const char *name, const struct utimbuf *ts)
     }
 }
 
+#else
+
+# include <sys/stat.h>
+# include "filename.h"
+
+int
+utime (const char *name, const struct utimbuf *ts)
+#undef utime
+{
+# if REPLACE_FUNC_UTIME_FILE
+  /* macOS 10.13 mistakenly succeeds when given a symbolic link to a
+     non-directory with a trailing slash.  */
+  size_t len = strlen (name);
+  if (ISSLASH (name[len - 1]))
+    {
+      struct stat buf;
+
+      if (stat (name, &buf) < 0)
+        return -1;
+    }
+# endif /* REPLACE_FUNC_UTIME_FILE */
+
+  return utime (name, ts);
+}
+
 #endif
index f0a82355523507578c6924197e340b32250e6518..3d2e13cb08cd7ab7bd882da0676a6f35b875c499 100644 (file)
@@ -1,4 +1,4 @@
-# utime.m4 serial 2
+# utime.m4 serial 3
 dnl Copyright (C) 2017-2020 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -8,6 +8,7 @@ AC_DEFUN([gl_FUNC_UTIME],
 [
   AC_REQUIRE([gl_UTIME_H_DEFAULTS])
   AC_REQUIRE([AC_CANONICAL_HOST])
+  AC_CHECK_FUNCS_ONCE([lstat])
   case "$host_os" in
     mingw*)
       dnl On this platform, the original utime() or _utime() produces
@@ -21,6 +22,51 @@ AC_DEFUN([gl_FUNC_UTIME],
       AC_CHECK_FUNCS([utime])
       if test $ac_cv_func_utime = no; then
         HAVE_UTIME=0
+      else
+        dnl On macOS 10.13, utime("link-to-file/", NULL) mistakenly succeeds.
+        AC_CACHE_CHECK([whether utime handles trailing slashes on files],
+          [gl_cv_func_utime_file_slash],
+          [touch conftest.tmp
+           # Assume that if we have lstat, we can also check symlinks.
+           if test $ac_cv_func_lstat = yes; then
+             ln -s conftest.tmp conftest.lnk
+           fi
+           AC_RUN_IFELSE(
+             [AC_LANG_PROGRAM(
+               [[#include <stddef.h>
+                 #include <time.h>
+               ]],
+               [[int result = 0;
+                 if (!utime ("conftest.tmp/", NULL))
+                   result |= 1;
+                 #if HAVE_LSTAT
+                 if (!utime ("conftest.lnk/", NULL))
+                   result |= 2;
+                 #endif
+                 return result;
+               ]])],
+             [gl_cv_func_utime_file_slash=yes],
+             [gl_cv_func_utime_file_slash=no],
+             [case "$host_os" in
+                                 # Guess yes on Linux systems.
+                linux-* | linux) gl_cv_func_utime_file_slash="guessing yes" ;;
+                                 # Guess yes on glibc systems.
+                *-gnu* | gnu*)   gl_cv_func_utime_file_slash="guessing yes" ;;
+                                 # Guess no on macOS.
+                darwin*)         gl_cv_func_utime_file_slash="guessing no" ;;
+                                 # If we don't know, obey --enable-cross-guesses.
+                *)               gl_cv_func_utime_file_slash="$gl_cross_guess_normal" ;;
+              esac
+             ])
+           rm -f conftest.tmp conftest.lnk
+          ])
+        case $gl_cv_func_stat_file_slash in
+          *no)
+            REPLACE_UTIME=1
+            AC_DEFINE([REPLACE_FUNC_UTIME_FILE], [1],
+              [Define to 1 if utime needs help when passed a file name with a trailing slash])
+            ;;
+        esac
       fi
       ;;
   esac
index 0fc34ebdc9ceaa2cbc0b602774fc6b500b79c3c7..d1975f47b342d7252eaea8ed87ab7678b33b425c 100644 (file)
@@ -10,6 +10,7 @@ utime-h
 time
 filename        [test $HAVE_UTIME = 0 || test $REPLACE_UTIME = 1]
 malloca         [test $HAVE_UTIME = 0 || test $REPLACE_UTIME = 1]
+stat            [test $HAVE_UTIME = 0 || test $REPLACE_UTIME = 1]
 
 configure.ac:
 gl_FUNC_UTIME