Skip to content

Commit 330fb05

Browse files
committed
Version bump to 0.2.1.
Added backpropagation from read-only caches to read-write ones.
1 parent b13da7a commit 330fb05

File tree

2 files changed

+28
-8
lines changed

2 files changed

+28
-8
lines changed

groovy_parser/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@
2121
__license__ = "Apache-2.0"
2222

2323
# https://www.python.org/dev/peps/pep-0396/
24-
__version__ = "0.2.0"
24+
__version__ = "0.2.1"

groovy_parser/parser.py

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import os
2626
import os.path
2727
import pathlib
28+
import shutil
2829
from typing import (
2930
cast,
3031
TYPE_CHECKING,
@@ -257,7 +258,13 @@ def parse_and_digest_groovy_content(
257258
# version of the software and its dependencies
258259
hreldir = h.copy().hexdigest()
259260

260-
ro_cache_paths: "MutableSequence[pathlib.Path]" = []
261+
this_cache_path = cache_path / hreldir
262+
this_cache_path.mkdir(parents=True, exist_ok=True)
263+
264+
# The first path to be inspected must the read-write one
265+
# so no spurious backpropagation operations from read-only to
266+
# already existing read-write one happen
267+
ro_cache_paths: "MutableSequence[pathlib.Path]" = [this_cache_path]
261268
if ro_cache_directories is not None:
262269
for ro_cache_directory in ro_cache_directories:
263270
if isinstance(ro_cache_directory, pathlib.Path):
@@ -270,11 +277,6 @@ def parse_and_digest_groovy_content(
270277
if this_ro_cache_path.is_dir():
271278
ro_cache_paths.append(this_ro_cache_path)
272279

273-
this_cache_path = cache_path / hreldir
274-
this_cache_path.mkdir(parents=True, exist_ok=True)
275-
276-
ro_cache_paths.append(this_cache_path)
277-
278280
# Now, let's go for the content signature
279281
h.update(content.encode("utf-8"))
280282
rel_hashpath = h.hexdigest() + ".json.gz"
@@ -289,7 +291,25 @@ def parse_and_digest_groovy_content(
289291
ro_hashpath.as_posix(), mode="rt", encoding="utf-8"
290292
) as jH:
291293
t_tree = json.load(jH)
292-
hashpath = None
294+
295+
# This is needed in order to propagate the cached
296+
# copy from the read-only cache
297+
try:
298+
assert hashpath is not None
299+
if not hashpath.samefile(ro_hashpath):
300+
# Removing possible stale copy
301+
if hashpath.exists():
302+
if hashpath.is_dir() and not hashpath.is_symlink():
303+
shutil.rmtree(hashpath.as_posix())
304+
else:
305+
hashpath.unlink()
306+
# New copy
307+
shutil.copy2(ro_hashpath.as_posix(), hashpath.as_posix())
308+
hashpath = None
309+
except:
310+
# If it cannot be created for some reason, try again later
311+
pass
312+
293313
break
294314
except:
295315
# If it is unreadable, re-create

0 commit comments

Comments
 (0)