MCPcopy Create free account
hub / github.com/FastLED/FastLED / _compute_file_hash

Function _compute_file_hash

ci/iwyu_cache.py:60–82  ·  view source on GitHub ↗

Compute SHA256 hash of file content + compiler args + source tree state. Args: file_path: Path to source file. compiler_args_key: String representation of compiler args. source_tree_hash: Combined hash of all header mtimes. Returns: Hex digest string.

(
    file_path: Path, compiler_args_key: str, source_tree_hash: str
)

Source from the content-addressed store, hash-verified

58
59
60def _compute_file_hash(
61 file_path: Path, compiler_args_key: str, source_tree_hash: str
62) -> str:
63 """Compute SHA256 hash of file content + compiler args + source tree state.
64
65 Args:
66 file_path: Path to source file.
67 compiler_args_key: String representation of compiler args.
68 source_tree_hash: Combined hash of all header mtimes.
69
70 Returns:
71 Hex digest string.
72 """
73 hasher = hashlib.sha256()
74 hasher.update(compiler_args_key.encode("utf-8"))
75 hasher.update(source_tree_hash.encode("utf-8"))
76 try:
77 with open(file_path, "rb") as f:
78 for chunk in iter(lambda: f.read(8192), b""):
79 hasher.update(chunk)
80 except OSError:
81 hasher.update(str(time.time()).encode("utf-8"))
82 return hasher.hexdigest()
83
84
85class IWYUCache:

Callers 2

getMethod · 0.85
putMethod · 0.85

Calls 3

timeMethod · 0.80
updateMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected