Commit d7ca5acd authored by Cyril Brulebois's avatar Cyril Brulebois
Browse files

lint_po: make each i18nspector work with a specific rply cache dir (Closes: #17359).

Treating the first PO file as special was a nice try but some files
don't trigger the creation of a parser, i.e. don't result in the
creation of a rply cache directory and/or cache file.

That's the case if the first file is wiki/src/getting_started.fr.po for
example, which results in various failure modes, depending on who wins
the race:
 - mkdir on the just-created rply directory;
 - trying to read from the just-created and still-empty cache file,
   which is not valid JSON-wise;
 - trying to read from a being-written cache file, leading to
   inconsistent data, meaning another JSON validity problem.

Therefore, consider the XDG_CACHE_HOME environment variable set at the
top-level to be the top-level directory, below which a specific
subdirectory will be created for each i18nspector call. This should
ensure nobody steps on someone else's toes.

This is just an attempt at a minimal bug fix, follow-up commits will
simplify that code drastically.
parent af71169b
......@@ -28,6 +28,7 @@ mypy lint_po
import argparse
import contextlib
import copy
import functools
import glob
import itertools
......@@ -221,7 +222,13 @@ def check_po_file(fname: str, extended: bool, i18nspector_env: Dict[str, str]) -
errors = list()
with pofile_readonly(fname) as poFile:
try:
issues = poFile.i18nspector(i18nspector_env)
# Make sure to have a specific subdirectory (#17359):
my_env = copy.copy(i18nspector_env)
with tempfile.TemporaryDirectory(
prefix="{dir}/".format(dir=my_env["XDG_CACHE_HOME"])) as tmpdir:
my_env["XDG_CACHE_HOME"] = tmpdir
issues = poFile.i18nspector(my_env)
if issues:
errors.append(
"i18nspector is not happy:\n\t"+"\n\t".join(issues))
......@@ -316,6 +323,9 @@ def main(logger) -> None:
# check only the headers
pool = multiprocessing.Pool()
with tempfile.TemporaryDirectory() as tmpXDGCacheHome:
# A per-child subdirectory will actually be used, to avoid
# race conditions between those populating the cache, and
# those who aren't (#17359):
i18nspector_env = {"XDG_CACHE_HOME": tmpXDGCacheHome}
_check_po_file = functools.partial(check_po_file,
extended=args.extended,
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment