Skip to content

Commit

Permalink
[fix] Set locale to C when calling GNU tar to get more reproducible o…
Browse files Browse the repository at this point in the history
…utput
  • Loading branch information
mxmlnkn committed Sep 27, 2024
1 parent 71768e8 commit 77c1ef8
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions ratarmount.py
Original file line number Diff line number Diff line change
Expand Up @@ -1753,14 +1753,32 @@ def addToDeletionFile(deletionListFile, pathRelativeToRoot: str):
print("Nothing to commit.")
return

# E.g. reproduce the bug with the script listed in https://github.com/mxmlnkn/ratarmount/issues/132:
# > sudo apt install language-pack-de
# Need to get 3,340 kB of archives.
# After this operation, 14.9 MB of additional disk space will be used.
# > LANG=de_DE.UTF-8 LANGUAGE=de_De tar
# tar: Eine der Optionen „-Acdtrux“, „--delete“ oder „--test-label“ ist notwendig
# „tar --help“ oder „tar --usage“ gibt weitere Informationen.
# > ls -la /usr/share/locale-langpack/de/LC_MESSAGES/tar.mo
# -rw-r--r-- 1 root root 63827 Aug 19 16:50 /usr/share/locale-langpack/de/LC_MESSAGES/tar.mo
# > LANG=de_DE.UTF-8 LANGUAGE=de_De bash issue-132.sh
def runWithoutLocale(*args, **kwargs):
adjustedEnvironment = os.environ.copy()
for key in [k for k in adjustedEnvironment.keys() if k.startswith('LC_')]:
del adjustedEnvironment[key]
adjustedEnvironment['LC_LANG'] = 'C'
adjustedEnvironment['LANGUAGE'] = 'C'
return subprocess.run(*args, env=adjustedEnvironment, **kwargs)

print()
print("Committing is an experimental feature!")
print('Please confirm by entering "commit". Any other input will cancel.')
print("> ", end='')
try:
if input() == 'commit':
if os.stat(deletionList).st_size > 0:
tarDelete = subprocess.run(
tarDelete = runWithoutLocale(
[
"tar",
"--delete",
Expand Down Expand Up @@ -1788,7 +1806,7 @@ def addToDeletionFile(deletionListFile, pathRelativeToRoot: str):
raise RatarmountError("There were problems when trying to delete files.")

if os.stat(appendList).st_size > 0:
subprocess.run(
runWithoutLocale(
[
"tar",
"--append",
Expand Down

0 comments on commit 77c1ef8

Please sign in to comment.