bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] gnulib-tool: Don't assume writable source


From: Bruno Haible
Subject: Re: [PATCH] gnulib-tool: Don't assume writable source
Date: Sat, 22 Feb 2020 15:18:42 +0100
User-agent: KMail/5.1.3 (Linux/4.4.0-171-generic; KDE/5.18.0; x86_64; ; )

Benno Fünfstück wrote:
> distributions also sometimes need to run gnulib-tool as part
> of a the build of a package (if the release tarball does not contain
> the required gnulib files or building directly from a git source if
> there is no release). In that case, it makes sense to have a package
> for gnulib to use in builds, also to ensure reproducibility.
> ...
> the store is read-only).

I understand.

Implemented like this. It should not slow down gnulib-tool significantly
in the common case, since 'test' is a shell built-in in most shells.


2020-02-22  Bruno Haible  <address@hidden>

        gnulib-tool: Ensure copied files are writable.
        Reported by Benno Fünfstück <address@hidden> in
        <https://lists.gnu.org/archive/html/bug-gnulib/2020-02/msg00101.html>.
        * gnulib-tool (func_ensure_writable): New function.
        (func_ln_s, func_hardlink, func_lookup_file, func_import,
        func_create_testdir, copy-file): Invoke it after copying a file.

diff --git a/gnulib-tool b/gnulib-tool
index 89f6077..01c6745 100755
--- a/gnulib-tool
+++ b/gnulib-tool
@@ -794,6 +794,13 @@ func_relconcat ()
   done
 }
 
+# func_ensure_writable DEST
+# Ensures the file DEST is writable.
+func_ensure_writable ()
+{
+  test -w "$1" || chmod u+w "$1"
+}
+
 # func_ln_s SRC DEST
 # Like ln -s, except use cp -p if ln -s fails.
 func_ln_s ()
@@ -813,6 +820,7 @@ func_ln_s ()
     esac
 
     cp -p "$cp_src" "$2"
+    func_ensure_writable "$2"
   }
 }
 
@@ -876,6 +884,7 @@ func_hardlink ()
   ln "$1" "$2" || {
     echo "$progname: ln failed; falling back on cp -p" >&2
     cp -p "$1" "$2"
+    func_ensure_writable "$2"
   }
 }
 
@@ -1717,6 +1726,7 @@ func_lookup_file ()
     lkbase=`echo "$lkfile" | sed -e 's,^.*/,,'`
     rm -f "$tmp/$lkbase"
     cp "$lookedup_file" "$tmp/$lkbase"
+    func_ensure_writable "$tmp/$lkbase"
     save_IFS="$IFS"
     IFS="$PATH_SEPARATOR"
     for patchfile in $lkpatches; do
@@ -5225,6 +5235,7 @@ s,^\(.................................................[^ 
]*\) *,
     func_dest_tmpfilename "$g"
     func_lookup_file "$f"
     cp "$lookedup_file" "$tmpfile" || func_fatal_error "failed"
+    func_ensure_writable "$tmpfile"
     case "$f" in
       *.class | *.mo )
         # Don't process binary files with sed.
@@ -6313,6 +6324,7 @@ func_create_testdir ()
       func_lookup_file "$f"
       if test -n "$lookedup_tmp"; then
         cp -p "$lookedup_file" "$testdir/$g"
+        func_ensure_writable "$testdir/$g"
       else
         func_should_link
         if test "$copyaction" = symlink; then
@@ -6322,6 +6334,7 @@ func_create_testdir ()
             func_hardlink "$lookedup_file" "$testdir/$g"
           else
             cp -p "$lookedup_file" "$testdir/$g"
+            func_ensure_writable "$testdir/$g"
           fi
         fi
       fi
@@ -7317,6 +7330,7 @@ s/\([.*$]\)/[\1]/g'
     # Copy the file.
     func_dest_tmpfilename "$g"
     cp "$lookedup_file" "$tmpfile" || func_fatal_error "failed"
+    func_ensure_writable "$tmpfile"
     already_present=true
     if test -f "$destdir/$g"; then
       # The file already exists.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]