]> Savannah Git Hosting - gnulib.git/commitdiff
gnulib-tool.py: Follow gnulib-tool changes, part 62.
authorCollin Funk <collin.funk1@gmail.com>
Sun, 17 Mar 2024 17:03:54 +0000 (10:03 -0700)
committerBruno Haible <bruno@clisp.org>
Sun, 17 Mar 2024 17:34:45 +0000 (18:34 +0100)
Follow gnulib-tool change
2020-02-22  Bruno Haible  <bruno@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
gnulib-tool.py.TODO
pygnulib/GLFileSystem.py
pygnulib/GLTestDir.py
pygnulib/constants.py
pygnulib/main.py

index e64d11c1781db5a2d5acc41dea4187791d3e8148..4463c454d6df9f3dd81e360ef374cc130e14e9f9 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2024-03-17  Collin Funk  <collin.funk1@gmail.com>
+
+       gnulib-tool.py: Follow gnulib-tool changes, part 62.
+       Follow gnulib-tool change
+       2020-02-22  Bruno Haible  <bruno@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-17  Bruno Haible  <bruno@clisp.org>
 
        gnulib-tool: Add undocumented option --gnulib-dir.
index 698f0d8ed2d265598af0c8833e9c2a7652548a6c..9a22e0ee7780081cd18b9ae6ced49acf4e9510f3 100644 (file)
@@ -128,21 +128,6 @@ Date:   Tue Dec 29 02:48:31 2020 +0100
 
 --------------------------------------------------------------------------------
 
-commit baec1bac1602ba8534320c295e120f7b658400f4
-Author: Bruno Haible <bruno@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.fuenfstueck@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 <bruno@clisp.org>
 Date:   Thu Jun 8 15:09:31 2017 +0200
index c199235e2e16a9e45e2ae995796354790c89ba06..72827c0547c25127f90601f18a061b71237e23f2 100644 (file)
@@ -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.
index d01893922cbded5a8839cc6645cbbb993ff8da48..156af057b56c7f6dc7a8dfb92ee237d74cfcd9eb 100644 (file)
@@ -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
index 975b0e7da2378ca3f4baaf66e51a7166e4484dd5..047ecf6e6f2b0e9aa752896e89ebeb40845623e5 100644 (file)
@@ -22,6 +22,7 @@ from __future__ import unicode_literals
 import re
 import os
 import sys
+import stat
 import platform
 import shutil
 import tempfile
@@ -300,6 +301,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 = '.'.
@@ -367,6 +376,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):
@@ -431,6 +441,7 @@ def hardlink(src: str, dest: str) -> None:
             else:
                 cp_src = src
         copyfile2(cp_src, dest)
+        ensure_writable(dest)
 
 
 def filter_filelist(separator, filelist,
index 7142414fb2decc22bfda66dbec727b8c5593a8f8..cf137ab616c00136656cde2c682203e52211ef41 100644 (file)
@@ -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
@@ -1270,6 +1271,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)