Pretty small patch. Just adds ensure_writable after copying files.

Collin

>From 224c3c910f88d22b825ad93e189ef6102487ad5a Mon Sep 17 00:00:00 2001
From: Collin Funk <collin.fu...@gmail.com>
Date: Sun, 17 Mar 2024 10:03:54 -0700
Subject: [PATCH] gnulib-tool.py: Follow gnulib-tool changes, part 62.

Follow gnulib-tool change
2020-02-22  Bruno Haible  <br...@clisp.org>
gnulib-tool: Ensure copied files are writable.

* pygnulib/constants.py (ensure_writable): New function. Make sure files
are writable.
(symlink_relative, hardlink): Use it.
* pygnulib/GLFileSystem.py (GLFileSystem.lookup)
(GLFileAssistant.add_or_update): Likewise.
* pygnulib/GLTestDir.py (GLTestDir.execute): Likewise.
* pygnulib/main.py (main): Likewise.
---
 ChangeLog                | 14 ++++++++++++++
 gnulib-tool.py.TODO      | 15 ---------------
 pygnulib/GLFileSystem.py |  3 +++
 pygnulib/GLTestDir.py    |  3 +++
 pygnulib/constants.py    | 11 +++++++++++
 pygnulib/main.py         |  2 ++
 6 files changed, 33 insertions(+), 15 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index be20514df2..f073d8abfe 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2024-03-17  Collin Funk  <collin.fu...@gmail.com>
+
+	gnulib-tool.py: Follow gnulib-tool changes, part 62.
+	Follow gnulib-tool change
+	2020-02-22  Bruno Haible  <br...@clisp.org>
+	gnulib-tool: Ensure copied files are writable.
+	* pygnulib/constants.py (ensure_writable): New function. Make sure files
+	are writable.
+	(symlink_relative, hardlink): Use it.
+	* pygnulib/GLFileSystem.py (GLFileSystem.lookup)
+	(GLFileAssistant.add_or_update): Likewise.
+	* pygnulib/GLTestDir.py (GLTestDir.execute): Likewise.
+	* pygnulib/main.py (main): Likewise.
+
 2024-03-16  Collin Funk  <collin.fu...@gmail.com>
 
 	gnulib-tool.py: Don't try to remove files that don't exist.
diff --git a/gnulib-tool.py.TODO b/gnulib-tool.py.TODO
index 698f0d8ed2..9a22e0ee77 100644
--- a/gnulib-tool.py.TODO
+++ b/gnulib-tool.py.TODO
@@ -128,21 +128,6 @@ Date:   Tue Dec 29 02:48:31 2020 +0100
 
 --------------------------------------------------------------------------------
 
-commit baec1bac1602ba8534320c295e120f7b658400f4
-Author: Bruno Haible <br...@clisp.org>
-Date:   Sat Feb 22 15:15:01 2020 +0100
-
-    gnulib-tool: Ensure copied files are writable.
-
-    Reported by Benno Fünfstück <benno.fuenfstu...@gmail.com> 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.
-
---------------------------------------------------------------------------------
-
 commit 30459fe101541698ec704acb224946d73676750e
 Author: Bruno Haible <br...@clisp.org>
 Date:   Thu Jun 8 15:09:31 2017 +0200
diff --git a/pygnulib/GLFileSystem.py b/pygnulib/GLFileSystem.py
index c199235e2e..72827c0547 100644
--- a/pygnulib/GLFileSystem.py
+++ b/pygnulib/GLFileSystem.py
@@ -43,6 +43,7 @@ joinpath = constants.joinpath
 copyfile = constants.copyfile
 movefile = constants.movefile
 hardlink = constants.hardlink
+ensure_writable = constants.ensure_writable
 link_if_changed = constants.link_if_changed
 isdir = os.path.isdir
 isfile = os.path.isfile
@@ -123,6 +124,7 @@ class GLFileSystem(object):
                 if isfile(tempFile):
                     os.remove(tempFile)
                 copyfile(lookedupFile, tempFile)
+                ensure_writable(tempFile)
                 for diff_in_localdir in reversed(lookedupPatches):
                     command = 'patch -s "%s" < "%s" >&2' % (tempFile, diff_in_localdir)
                     try:  # Try to apply patch
@@ -361,6 +363,7 @@ class GLFileAssistant(object):
         sed_transform_testsrelated_lib_file = self.transformers.get('tests', '')
         try:  # Try to copy lookedup file to tmpfile
             copyfile(lookedup, tmpfile)
+            ensure_writable(tmpfile)
         except Exception as error:
             raise GLError(15, lookedup)
         # Don't process binary files with sed.
diff --git a/pygnulib/GLTestDir.py b/pygnulib/GLTestDir.py
index d01893922c..156af057b5 100644
--- a/pygnulib/GLTestDir.py
+++ b/pygnulib/GLTestDir.py
@@ -52,6 +52,7 @@ TESTS = constants.TESTS
 joinpath = constants.joinpath
 relinverse = constants.relinverse
 copyfile = constants.copyfile
+ensure_writable = constants.ensure_writable
 movefile = constants.movefile
 isdir = os.path.isdir
 isfile = os.path.isfile
@@ -364,6 +365,7 @@ class GLTestDir(object):
                 os.remove(destpath)
             if flag:
                 copyfile(lookedup, destpath)
+                ensure_writable(destpath)
             else:  # if not flag
                 if self.filesystem.shouldLink(src, lookedup) == CopyAction.Symlink:
                     constants.link_relative(lookedup, destpath)
@@ -371,6 +373,7 @@ class GLTestDir(object):
                     constants.hardlink(lookedup, destpath)
                 else:
                     copyfile(lookedup, destpath)
+                    ensure_writable(destpath)
 
         # Create $sourcebase/Makefile.am.
         for_test = True
diff --git a/pygnulib/constants.py b/pygnulib/constants.py
index dc2e68069d..ee060c7b3c 100644
--- a/pygnulib/constants.py
+++ b/pygnulib/constants.py
@@ -22,6 +22,7 @@ from __future__ import unicode_literals
 import re
 import os
 import sys
+import stat
 import platform
 import shutil
 import tempfile
@@ -299,6 +300,14 @@ def relconcat(dir1, dir2):
     return os.path.normpath(os.path.join(dir1, dir2))
 
 
+def ensure_writable(dest: str) -> None:
+    '''Ensure that the file dest is writable.'''
+    # os.stat throws FileNotFoundError error but we assume it exists.
+    st = os.stat(dest)
+    if not (st.st_mode & stat.S_IWUSR):
+        os.chmod(dest, st.st_mode | stat.S_IWUSR)
+
+
 def relinverse(dir):
     '''Compute the inverse of dir. Namely, a relative pathname consisting only
     of '..' components, such that dir/relinverse = '.'.
@@ -366,6 +375,7 @@ def symlink_relative(src, dest):
             else:
                 cp_src = src
         copyfile2(cp_src, dest)
+        ensure_writable(dest)
 
 
 def as_link_value_at_dest(src, dest):
@@ -430,6 +440,7 @@ def hardlink(src: str, dest: str) -> None:
             else:
                 cp_src = src
         copyfile2(cp_src, dest)
+        ensure_writable(dest)
 
 
 def filter_filelist(separator, filelist,
diff --git a/pygnulib/main.py b/pygnulib/main.py
index 5d88d0115a..04cdfdbbf4 100644
--- a/pygnulib/main.py
+++ b/pygnulib/main.py
@@ -80,6 +80,7 @@ MODES = constants.MODES
 TESTS = constants.TESTS
 joinpath = constants.joinpath
 copyfile = constants.copyfile
+ensure_writable = constants.ensure_writable
 isabs = os.path.isabs
 isdir = os.path.isdir
 isfile = os.path.isfile
@@ -1257,6 +1258,7 @@ def main():
         assistant = classes.GLFileAssistant(config)
         tmpfile = assistant.tmpfilename(destpath)
         copyfile(lookedup, tmpfile)
+        ensure_writable(tmpfile)
         assistant.setOriginal(srcpath)
         assistant.config.setDestDir(destdir)
         assistant.setRewritten(destpath)
-- 
2.44.0

Reply via email to