]> Savannah Git Hosting - gnulib.git/commitdiff
gnulib-tool.py: Avoid errors when writing to a VFAT file system.
authorBruno Haible <bruno@clisp.org>
Wed, 3 Aug 2022 09:27:21 +0000 (11:27 +0200)
committerBruno Haible <bruno@clisp.org>
Wed, 3 Aug 2022 09:27:21 +0000 (11:27 +0200)
* pygnulib/constants.py (copyfile, copyfile2): New functions.
* gnulib-tool.py: Use them instead of shutil.
* pygnulib/*.py: Likewise.

ChangeLog
gnulib-tool.py
pygnulib/GLFileSystem.py
pygnulib/GLImport.py
pygnulib/GLTestDir.py
pygnulib/constants.py

index 419ea2fbd5e346fccc7f078da940c6972cb45a16..fe8225b5df88a19fad9f6c92fa337104992a209e 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 2022-08-03  Bruno Haible  <bruno@clisp.org>
 
+       gnulib-tool.py: Avoid errors when writing to a VFAT file system.
+       * pygnulib/constants.py (copyfile, copyfile2): New functions.
+       * gnulib-tool.py: Use them instead of shutil.
+       * pygnulib/*.py: Likewise.
+
        gnulib-tool.py: Fix typo.
        * pygnulib/GLImport.py (GLImport.__init__): Use the relative auxdir as
        second, not as first argument of joinpath.
index 302aaf340595c87be11cd2d393981043ef04b63a..2ac522aa05758e3a953bdbb9c16dae048736d1fd 100755 (executable)
@@ -54,6 +54,7 @@ MODES = constants.MODES
 TESTS = constants.TESTS
 compiler = constants.compiler
 joinpath = constants.joinpath
+copyfile = constants.copyfile
 isabs = os.path.isabs
 isdir = os.path.isdir
 isfile = os.path.isfile
@@ -959,7 +960,7 @@ def main():
         # Copy the file.
         assistant = classes.GLFileAssistant(config)
         tmpfile = assistant.tmpfilename(destpath)
-        shutil.copy(lookedup, tmpfile)
+        copyfile(lookedup, tmpfile)
         assistant.setOriginal(srcpath)
         assistant.config.setDestDir(destdir)
         assistant.setRewritten(destpath)
index dfb1bb903f9aee05a78bb50d194d514af88252e2..5368f3c1b8353751baa40199044e609ca04a0300 100644 (file)
@@ -42,6 +42,7 @@ __copyright__ = constants.__copyright__
 #===============================================================================
 DIRS = constants.DIRS
 joinpath = constants.joinpath
+copyfile = constants.copyfile
 isdir = os.path.isdir
 isfile = os.path.isfile
 
@@ -118,7 +119,7 @@ class GLFileSystem(object):
                     pass  # Skip errors if directory exists
                 if isfile(tempFile):
                     os.remove(tempFile)
-                shutil.copy(lookedupFile, tempFile)
+                copyfile(lookedupFile, tempFile)
                 for diff_in_localdir in reversed(lookedupPatches):
                     command = 'patch -s "%s" < "%s" >&2' % (tempFile, diff_in_localdir)
                     try:  # Try to apply patch
@@ -317,7 +318,7 @@ class GLFileAssistant(object):
                     try:  # Try to move file
                         if os.path.exists(basepath):
                             os.remove(basepath)
-                        shutil.copy(tmpfile, rewritten)
+                        copyfile(tmpfile, rewritten)
                     except Exception as error:
                         raise GLError(17, original)
             else:  # if self.config['dryrun']
@@ -352,7 +353,7 @@ class GLFileAssistant(object):
         sed_transform_testsrelated_lib_file = self.transformers.get(
             'tests', '')
         try:  # Try to copy lookedup file to tmpfile
-            shutil.copy(lookedup, tmpfile)
+            copyfile(lookedup, tmpfile)
         except Exception as error:
             raise GLError(15, lookedup)
         # Don't process binary files with sed.
index 5009917e7666ce81b63fbddbe5a0775739c52188..cbee0c4f3315abf994df92a9272ac17e7c1f0d97 100644 (file)
@@ -52,6 +52,7 @@ TESTS = constants.TESTS
 compiler = constants.compiler
 joinpath = constants.joinpath
 cleaner = constants.cleaner
+copyfile2 = constants.copyfile2
 isabs = os.path.isabs
 isdir = os.path.isdir
 isfile = os.path.isfile
@@ -734,7 +735,7 @@ AC_DEFUN([%s_FILE_LIST], [\n''' % macro_prefix
                     if not self.config['dryrun']:
                         print('Updating %s (backup in %s)' %
                               (srcpath, backupname))
-                        shutil.copy2(srcpath, backupname)
+                        copyfile2(srcpath, backupname)
                         result = ''
                         with codecs.open(srcpath, 'ab', 'UTF-8') as file:
                             file.write(destdata)
index 36aa5d21171605273a303958afd101e08cd8f694..c230fbc744341fa7fd3ba83aea1524214e1e0057 100644 (file)
@@ -53,6 +53,7 @@ UTILS = constants.UTILS
 TESTS = constants.TESTS
 compiler = constants.compiler
 joinpath = constants.joinpath
+copyfile = constants.copyfile
 isdir = os.path.isdir
 isfile = os.path.isfile
 normpath = os.path.normpath
@@ -333,12 +334,12 @@ class GLTestDir(object):
             if isfile(destpath):
                 os.remove(destpath)
             if flag:
-                shutil.copy(lookedup, destpath)
+                copyfile(lookedup, destpath)
             else:  # if not flag
                 if self.filesystem.shouldLink(src, lookedup) == CopyAction.Symlink:
                     constants.link_relative(lookedup, destpath)
                 else:
-                    shutil.copy(lookedup, destpath)
+                    copyfile(lookedup, destpath)
 
         # Create $sourcebase/Makefile.am.
         for_test = True
index 91a2958eb3ae441692ac738e0a4d7e41bb222333..cf6f05eb987bc20e3ce8bf524bb3f8811fad4d47 100644 (file)
@@ -23,6 +23,7 @@ import re
 import os
 import sys
 import platform
+import shutil
 import tempfile
 import subprocess as sp
 import __main__ as interpreter
@@ -303,6 +304,27 @@ def relconcat(dir1, dir2):
     return os.path.normpath(os.path.join(dir1, dir2))
 
 
+def copyfile(src, dest):
+    '''Copy file src to file dest. Like shutil.copy, but ignore errors e.g. on
+    VFAT file systems.'''
+    shutil.copyfile(src, dest)
+    try:
+        shutil.copymode(src, dest)
+    except PermissionError:
+        pass
+
+
+def copyfile2(src, dest):
+    '''Copy file src to file dest, preserving modification time. Like
+    shutil.copy2, but ignore errors e.g. on VFAT file systems. This function
+    is to be used for backup files.'''
+    shutil.copyfile(src, dest)
+    try:
+        shutil.copystat(src, dest)
+    except PermissionError:
+        pass
+
+
 def link_relative(src, dest):
     '''Like ln -s, except that src is given relative to the current directory
     (or absolute), not given relative to the directory of dest.'''