From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-Status: No, score=-3.7 required=3.0 tests=AWL,BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, NICE_REPLY_A,RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL, SPF_HELO_PASS,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id 8BE821FB0A for ; Fri, 4 Dec 2020 23:24:14 +0000 (UTC) Received: from localhost ([::1]:47674 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1klKQv-0001gN-84 for normalperson@yhbt.net; Fri, 04 Dec 2020 18:24:13 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:55218) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1klKQr-0001gE-Cd for bug-gnulib@gnu.org; Fri, 04 Dec 2020 18:24:09 -0500 Received: from mo4-p00-ob.smtp.rzone.de ([81.169.146.163]:36674) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1klKQo-0001St-Fe for bug-gnulib@gnu.org; Fri, 04 Dec 2020 18:24:09 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1607124242; s=strato-dkim-0002; d=clisp.org; h=References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: X-RZG-CLASS-ID:X-RZG-AUTH:From:Subject:Sender; bh=M8sAKiH148OPodWVOQsQWx2I3XWCGg4xfUe/3isRYac=; b=Or3vNLq9dQLMoSyfT25e6gAXygDyHV3sTETm4p4BeA/9hCCZtCS1lAPFViwhPU6CXs G0XM1jTHGK2Bj3BF7guDIrXZEFCSNGljVeoHHAc2Dvu/iv5JQLi/YrvBnSGWEpLnQzaz NwkSSzNRAQ0OVtyZZfjvae6TNLr9S4bZhF5XVTvcTmuQXPB2/n/+WhAxTRmz2wPk4H2j +ygltsjb0CIgGLCykgrJWI2vulnjLTGULotCeek7QBm7V5XckfZLq0aI9HBkgZBortCU Pvb49IlgjBIcKqvNYdo2v97Q+QSLlxz0s3lEIaKvWh6dpC+yUCeSfmEzesOQQMzNHAYF kyaQ== X-RZG-AUTH: ":Ln4Re0+Ic/6oZXR1YgKryK8brlshOcZlIWs+iCP5vnk6shH+AHjwLuWOGaf0yJVW" X-RZG-CLASS-ID: mo00 Received: from bruno.haible.de by smtp.strato.de (RZmta 47.3.4 DYNA|AUTH) with ESMTPSA id V00800wB4NO07aW (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (curve X9_62_prime256v1 with 256 ECDH bits, eq. 3072 bits RSA)) (Client did not present a certificate); Sat, 5 Dec 2020 00:24:00 +0100 (CET) From: Bruno Haible To: bug-gnulib@gnu.org Subject: Re: utime on macOS Date: Sat, 05 Dec 2020 00:24:00 +0100 Message-ID: <12658255.5VkcuPUL5K@omega> User-Agent: KMail/5.1.3 (Linux/4.4.0-193-generic; KDE/5.18.0; x86_64; ; ) In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="iso-8859-1" Received-SPF: none client-ip=81.169.146.163; envelope-from=bruno@clisp.org; helo=mo4-p00-ob.smtp.rzone.de X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, NICE_REPLY_A=-0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: bug-gnulib@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Gnulib discussion list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Martin =?ISO-8859-1?Q?Storsj=F6?= Errors-To: bug-gnulib-bounces+normalperson=yhbt.net@gnu.org Sender: "bug-gnulib" Martin Storsj=F6 wrote: > FAIL: test-utime When I add an autoconf test for the trailing slash handling in utime(), I g= et: checking whether utime handles trailing slashes on files... no along with checking whether lstat correctly handles trailing slash... no checking whether stat handles trailing slashes on files... no checking whether open recognizes a trailing slash... no checking whether symlink handles trailing slash correctly... no This patch fixes it. Since utime() has side effects, we have to check for the trailing slash before invoking utime(). 2020-12-04 Bruno Haible utime: Fix a test failure on macOS 10.13. Reported by Martin Storsj=F6 in . * 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. diff --git a/doc/posix-functions/lstat.texi b/doc/posix-functions/lstat.texi index 1b1aff6..1a1ffb4 100644 =2D-- a/doc/posix-functions/lstat.texi +++ b/doc/posix-functions/lstat.texi @@ -24,7 +24,7 @@ Solaris 9. @item On some platforms, @code{lstat("file/",buf)} succeeds instead of failing with @code{ENOTDIR}. =2DSolaris 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 diff --git a/doc/posix-functions/open.texi b/doc/posix-functions/open.texi index d4767d9..7e4f187 100644 =2D-- a/doc/posix-functions/open.texi +++ b/doc/posix-functions/open.texi @@ -19,7 +19,7 @@ correctly with files larger than 2 GB@. (Cf. @code{AC_SY= S_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: =2DFreeBSD 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 defin= ed by the gnulib module @code{nonblocking} on some platforms: diff --git a/doc/posix-functions/stat.texi b/doc/posix-functions/stat.texi index 27fbe27..1d1f927 100644 =2D-- a/doc/posix-functions/stat.texi +++ b/doc/posix-functions/stat.texi @@ -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}. =2DFreeBSD 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: diff --git a/doc/posix-functions/symlink.texi b/doc/posix-functions/symlink= =2Etexi index 88d1c77..3826ccf 100644 =2D-- a/doc/posix-functions/symlink.texi +++ b/doc/posix-functions/symlink.texi @@ -11,7 +11,7 @@ Portability problems fixed by Gnulib: @item On some systems, @code{symlink(value,"name/")} mistakenly creates a symlink: =2DFreeBSD 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}: diff --git a/doc/posix-functions/utime.texi b/doc/posix-functions/utime.texi index d019c4a..4e41e5d 100644 =2D-- a/doc/posix-functions/utime.texi +++ b/doc/posix-functions/utime.texi @@ -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 =20 Portability problems not fixed by Gnulib: diff --git a/lib/utime.c b/lib/utime.c index c35eb16..f6465a3 100644 =2D-- a/lib/utime.c +++ b/lib/utime.c @@ -259,4 +259,29 @@ utime (const char *name, const struct utimbuf *ts) } } =20 +#else + +# include +# 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 =3D 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 diff --git a/m4/utime.m4 b/m4/utime.m4 index f0a8235..3d2e13c 100644 =2D-- a/m4/utime.m4 +++ b/m4/utime.m4 @@ -1,4 +1,4 @@ =2D# 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 =3D no; then HAVE_UTIME=3D0 + else + dnl On macOS 10.13, utime("link-to-file/", NULL) mistakenly succee= ds. + 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 =3D yes; then + ln -s conftest.tmp conftest.lnk + fi + AC_RUN_IFELSE( + [AC_LANG_PROGRAM( + [[#include + #include + ]], + [[int result =3D 0; + if (!utime ("conftest.tmp/", NULL)) + result |=3D 1; + #if HAVE_LSTAT + if (!utime ("conftest.lnk/", NULL)) + result |=3D 2; + #endif + return result; + ]])], + [gl_cv_func_utime_file_slash=3Dyes], + [gl_cv_func_utime_file_slash=3Dno], + [case "$host_os" in + # Guess yes on Linux systems. + linux-* | linux) gl_cv_func_utime_file_slash=3D"guessing y= es" ;; + # Guess yes on glibc systems. + *-gnu* | gnu*) gl_cv_func_utime_file_slash=3D"guessing y= es" ;; + # Guess no on macOS. + darwin*) gl_cv_func_utime_file_slash=3D"guessing n= o" ;; + # If we don't know, obey --enable-cross-g= uesses. + *) gl_cv_func_utime_file_slash=3D"$gl_cross_= guess_normal" ;; + esac + ]) + rm -f conftest.tmp conftest.lnk + ]) + case $gl_cv_func_stat_file_slash in + *no) + REPLACE_UTIME=3D1 + AC_DEFINE([REPLACE_FUNC_UTIME_FILE], [1], + [Define to 1 if utime needs help when passed a file name wit= h a trailing slash]) + ;; + esac fi ;; esac diff --git a/modules/utime b/modules/utime index 0fc34eb..d1975f4 100644 =2D-- a/modules/utime +++ b/modules/utime @@ -10,6 +10,7 @@ utime-h time filename [test $HAVE_UTIME =3D 0 || test $REPLACE_UTIME =3D 1] malloca [test $HAVE_UTIME =3D 0 || test $REPLACE_UTIME =3D 1] +stat [test $HAVE_UTIME =3D 0 || test $REPLACE_UTIME =3D 1] =20 configure.ac: gl_FUNC_UTIME