* pygnulib/constants.py (copyfile, copyfile2): New functions.
* gnulib-tool.py: Use them instead of shutil.
* pygnulib/*.py: Likewise.
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.
TESTS = constants.TESTS
compiler = constants.compiler
joinpath = constants.joinpath
+copyfile = constants.copyfile
isabs = os.path.isabs
isdir = os.path.isdir
isfile = os.path.isfile
# 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)
#===============================================================================
DIRS = constants.DIRS
joinpath = constants.joinpath
+copyfile = constants.copyfile
isdir = os.path.isdir
isfile = os.path.isfile
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
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']
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.
compiler = constants.compiler
joinpath = constants.joinpath
cleaner = constants.cleaner
+copyfile2 = constants.copyfile2
isabs = os.path.isabs
isdir = os.path.isdir
isfile = os.path.isfile
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)
TESTS = constants.TESTS
compiler = constants.compiler
joinpath = constants.joinpath
+copyfile = constants.copyfile
isdir = os.path.isdir
isfile = os.path.isfile
normpath = os.path.normpath
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
import os
import sys
import platform
+import shutil
import tempfile
import subprocess as sp
import __main__ as interpreter
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.'''