[rtems-central commit] items: Fix ItemCache construction

Sebastian Huber sebh at rtems.org
Mon Dec 14 15:56:19 UTC 2020


Module:    rtems-central
Branch:    master
Commit:    b3bdac2ee72620da03efcb9f220750d7c6d5fe4f
Changeset: http://git.rtems.org/rtems-central/commit/?id=b3bdac2ee72620da03efcb9f220750d7c6d5fe4f

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Mon Dec 14 16:09:18 2020 +0100

items: Fix ItemCache construction

Use a separate cache directory for each specification item base
directory.

---

 rtemsspec/items.py                      | 10 +++++-----
 rtemsspec/tests/test_items_itemcache.py |  5 +++--
 2 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/rtemsspec/items.py b/rtemsspec/items.py
index cc46338..0e22f64 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 a45f4fc..922e622 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"]



More information about the vc mailing list