From: Collin Funk Date: Sun, 17 Mar 2024 17:03:54 +0000 (-0700) Subject: gnulib-tool.py: Follow gnulib-tool changes, part 62. X-Git-Tag: v1.0~274 X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=d64fd23bdc70b7005e86bae3fd5e8212c257b6e2;p=gnulib.git gnulib-tool.py: Follow gnulib-tool changes, part 62. Follow gnulib-tool change 2020-02-22 Bruno Haible 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. --- diff --git a/ChangeLog b/ChangeLog index e64d11c178..4463c454d6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +2024-03-17 Collin Funk + + gnulib-tool.py: Follow gnulib-tool changes, part 62. + Follow gnulib-tool change + 2020-02-22 Bruno Haible + 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 gnulib-tool: Add undocumented option --gnulib-dir. 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 -Date: Sat Feb 22 15:15:01 2020 +0100 - - gnulib-tool: Ensure copied files are writable. - - Reported by Benno Fünfstück in - . - - * 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 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 975b0e7da2..047ecf6e6f 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 @@ -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, diff --git a/pygnulib/main.py b/pygnulib/main.py index 7142414fb2..cf137ab616 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 @@ -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)