[rtems-central commit] items: Detect file removals in item cache

Sebastian Huber sebh at rtems.org
Wed Oct 28 06:58:20 UTC 2020


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

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Wed Oct 28 07:44:11 2020 +0100

items: Detect file removals in item cache

---

 rtemsspec/items.py                      | 5 ++++-
 rtemsspec/tests/test_items_itemcache.py | 4 ++++
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/rtemsspec/items.py b/rtemsspec/items.py
index e9f1c0e..d7f96a4 100644
--- a/rtemsspec/items.py
+++ b/rtemsspec/items.py
@@ -576,10 +576,13 @@ class ItemCache:
             update_cache = False
         except FileNotFoundError:
             update_cache = True
+        else:
+            update_cache = mtime <= os.path.getmtime(path)
         for name in os.listdir(path):
             path2 = os.path.join(path, name)
             if name.endswith(".yml") and not name.startswith("."):
-                update_cache = update_cache or mtime <= os.path.getmtime(path2)
+                if not update_cache:
+                    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)
diff --git a/rtemsspec/tests/test_items_itemcache.py b/rtemsspec/tests/test_items_itemcache.py
index b220586..0aaacb2 100644
--- a/rtemsspec/tests/test_items_itemcache.py
+++ b/rtemsspec/tests/test_items_itemcache.py
@@ -65,6 +65,10 @@ def test_load(tmpdir):
     assert item.uid == "/foo/bar"
     assert item.type == ""
     assert item["type"] == "spec"
+    os.remove(os.path.join(tmpdir, "spec", "d", "c.yml"))
+    item_cache_4 = ItemCache(config)
+    with pytest.raises(KeyError):
+        item_cache_4["/d/c"]
 
 
 def test_load_link_error(tmpdir):



More information about the vc mailing list