You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@buildstream.apache.org by ju...@apache.org on 2026/10/16 12:55:18 UTC
(buildstream) 03/04: cascache.py: Detect duplicate `Directory` node names
This is an automated email from the ASF dual-hosted git repository.
juergbi pushed a commit to branch jbilleter/directory-validation
in repository https://gitbox.apache.org/repos/asf/buildstream.git
commit 347f3d5e40d2ae0a1c96997f29191b2b9e43d6b3
Author: Jürg Billeter <j...@bitron.ch>
AuthorDate: Fri Oct 2 14:31:34 2026 +0200
cascache.py: Detect duplicate `Directory` node names
The REAPI spec requires that each child in the directory must have a
unique path segment (file name).
---
src/buildstream/_cas/cascache.py | 15 +++++++++++----
1 file changed, 11 insertions(+), 4 deletions(-)
diff --git a/src/buildstream/_cas/cascache.py b/src/buildstream/_cas/cascache.py
index 385bc97e5..c649e21bf 100644
--- a/src/buildstream/_cas/cascache.py
+++ b/src/buildstream/_cas/cascache.py
@@ -185,8 +185,10 @@ class CASCache:
with open(self.objpath(tree), "rb") as f:
directory.ParseFromString(f.read())
+ names = set[str]()
+
for filenode in directory.files:
- _validate_cas_node_name(filenode.name)
+ _validate_cas_node_name(filenode.name, names)
# regular file, create hardlink
fullpath = os.path.join(dest, filenode.name)
@@ -216,13 +218,13 @@ class CASCache:
os.chmod(fullpath, mode)
for dirnode in directory.directories:
- _validate_cas_node_name(dirnode.name)
+ _validate_cas_node_name(dirnode.name, names)
fullpath = os.path.join(dest, dirnode.name)
self.checkout(fullpath, dirnode.digest, can_link=can_link, _fetch=False)
for symlinknode in directory.symlinks:
# symlink
- _validate_cas_node_name(symlinknode.name)
+ _validate_cas_node_name(symlinknode.name, names)
fullpath = os.path.join(dest, symlinknode.name)
os.symlink(symlinknode.target, fullpath)
@@ -835,9 +837,14 @@ def _grouper(iterable, n):
#
# Args:
# name (str): The name of a CAS Directory entry
+# names (set): The set of names in the directory
#
-def _validate_cas_node_name(name: str):
+def _validate_cas_node_name(name: str, names: set[str]):
if os.path.basename(name) != name or name in ("", ".", ".."):
raise CASCacheError(
f"Invalid name in a CAS Directory node: '{name}' (every child in the directory must have a path of exactly one segment)"
)
+
+ if name in names:
+ raise CASCacheError(f"Duplicate name in a CAS Directory node: '{name}'")
+ names.add(name)