summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2020-12-14 16:09:18 +0100
committerSebastian Huber <sebastian.huber@embedded-brains.de>2020-12-14 16:56:03 +0100
commitb3bdac2ee72620da03efcb9f220750d7c6d5fe4f (patch)
treee3b1ad236939ae153c2591ad19e6981e8c4adc02
parentitems: Simplify ItemMapper (diff)
downloadrtems-central-b3bdac2ee72620da03efcb9f220750d7c6d5fe4f.tar.bz2
items: Fix ItemCache construction
Use a separate cache directory for each specification item base directory.
-rw-r--r--rtemsspec/items.py10
-rw-r--r--rtemsspec/tests/test_items_itemcache.py5
2 files changed, 8 insertions, 7 deletions
diff --git a/rtemsspec/items.py b/rtemsspec/items.py
index cc46338a..0e22f640 100644
--- a/rtemsspec/items.py
+++ b/rtemsspec/items.py
@@ -550,8 +550,8 @@ class ItemCache:
self._items = {} # type: ItemMap
self._updates = 0
cache_dir = os.path.abspath(config["cache-directory"])
- for path in config["paths"]:
- self._load_items_recursive(path, path, cache_dir)
+ for index, path in enumerate(config["paths"]):
+ self._load_items_recursive(str(index), path, path, cache_dir)
if post_process_load:
post_process_load(self._items)
self._init_parents()
@@ -618,11 +618,11 @@ class ItemCache:
for uid, data in iter(data_by_uid.items()):
self._add_item(uid, data)
- def _load_items_recursive(self, base: str, path: str,
+ def _load_items_recursive(self, index: str, base: str, path: str,
cache_dir: str) -> None:
mid = os.path.abspath(path)
mid = mid.replace(os.path.commonpath([cache_dir, mid]), "").strip("/")
- cache_file = os.path.join(cache_dir, mid, "spec.pickle")
+ cache_file = os.path.join(cache_dir, index, mid, "spec.pickle")
try:
mtime = os.path.getmtime(cache_file)
update_cache = False
@@ -637,7 +637,7 @@ class ItemCache:
update_cache = mtime <= os.path.getmtime(path2)
else:
if stat.S_ISDIR(os.lstat(path2).st_mode):
- self._load_items_recursive(base, path2, cache_dir)
+ self._load_items_recursive(index, base, path2, cache_dir)
self._load_items_in_dir(base, path, cache_file, update_cache)
def _init_parents(self) -> None:
diff --git a/rtemsspec/tests/test_items_itemcache.py b/rtemsspec/tests/test_items_itemcache.py
index a45f4fc1..922e6220 100644
--- a/rtemsspec/tests/test_items_itemcache.py
+++ b/rtemsspec/tests/test_items_itemcache.py
@@ -48,8 +48,9 @@ def test_load(tmpdir):
assert item_count == len(item_cache.all)
assert item_cache.updates
cache_dir = config["cache-directory"]
- assert os.path.exists(os.path.join(cache_dir, "spec", "spec.pickle"))
- assert os.path.exists(os.path.join(cache_dir, "spec", "d", "spec.pickle"))
+ assert os.path.exists(os.path.join(cache_dir, "0", "spec", "spec.pickle"))
+ assert os.path.exists(
+ os.path.join(cache_dir, "0", "spec", "d", "spec.pickle"))
assert item_cache["/d/c"]["v"] == "c"
assert item_cache["/p"]["v"] == "p"
p = item_cache["/p"]