(
cache_dir: str, diff_file: str, sqlite: bool = False, num_shards: int = SQLITE_NUM_SHARDS
)
| 32 | |
| 33 | |
| 34 | def apply_diff( |
| 35 | cache_dir: str, diff_file: str, sqlite: bool = False, num_shards: int = SQLITE_NUM_SHARDS |
| 36 | ) -> None: |
| 37 | cache = make_cache(cache_dir, sqlite, num_shards=num_shards) |
| 38 | with open(diff_file, "rb") as f: |
| 39 | diff = json_loads(f.read()) |
| 40 | |
| 41 | old_deps = json_loads(cache.read("@deps.meta.json")) |
| 42 | |
| 43 | for file, data in diff.items(): |
| 44 | if data is None: |
| 45 | cache.remove(file) |
| 46 | else: |
| 47 | if file.endswith(".ff"): |
| 48 | data_bytes = base64.b64decode(data) |
| 49 | else: |
| 50 | data_bytes = data.encode() if isinstance(data, str) else data |
| 51 | cache.write(file, data_bytes) |
| 52 | if file.endswith(".meta.ff") and "@deps" not in file: |
| 53 | buf = ReadBuffer(data_bytes[2:]) |
| 54 | meta = CacheMeta.read(buf, data_file="") |
| 55 | assert meta is not None |
| 56 | old_deps["snapshot"][meta.id] = meta.hash |
| 57 | elif file.endswith(".meta.json") and "@deps" not in file: |
| 58 | meta_dict = json_loads(data_bytes) |
| 59 | old_deps["snapshot"][meta_dict["id"]] = meta_dict["hash"] |
| 60 | |
| 61 | cache.write("@deps.meta.json", json_dumps(old_deps)) |
| 62 | |
| 63 | cache.commit() |
| 64 | |
| 65 | |
| 66 | def main() -> None: |
no test coverage detected
searching dependent graphs…