Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/buildstream/_cas/cascache.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import itertools
import os
import re
import stat
import contextlib
import time
Expand All @@ -41,6 +42,10 @@
_CACHE_USAGE_REFRESH = 5


# Constant for SHA-256 validation (64 hexadecimal digits)
_HASH_REGEX = re.compile(r"[0-9a-f]{64}")


class CASLogLevel(FastEnum):
WARNING = "warning"
INFO = "info"
Expand Down Expand Up @@ -323,6 +328,9 @@ def pull_tree(self, remote, digest):
# (str): The path of the object
#
def objpath(self, digest):
if not _HASH_REGEX.fullmatch(digest.hash):
raise ValueError(f"Invalid hash: `{digest.hash}`")

return os.path.join(self.casdir, "objects", digest.hash[:2], digest.hash[2:])

# open():
Expand Down
Loading