Update the cache file data and write a new cache file.
(self, sources: Iterable[Path])
| 131 | return changed, done |
| 132 | |
| 133 | def write(self, sources: Iterable[Path]) -> None: |
| 134 | class="st">""class="st">"Update the cache file data and write a new cache file."class="st">"" |
| 135 | self.file_data.update( |
| 136 | **{str(src.resolve()): Cache.get_file_data(src) for src in sources} |
| 137 | ) |
| 138 | try: |
| 139 | CACHE_DIR.mkdir(parents=True, exist_ok=True) |
| 140 | with tempfile.NamedTemporaryFile( |
| 141 | dir=str(self.cache_file.parent), delete=False |
| 142 | ) as f: |
| 143 | class="cm"># We store raw tuples in the cache because it's faster. |
| 144 | data: dict[str, tuple[float, int, str]] = { |
| 145 | k: (*v,) for k, v in self.file_data.items() |
| 146 | } |
| 147 | pickle.dump(data, f, protocol=4) |
| 148 | os.replace(f.name, self.cache_file) |
| 149 | except OSError: |
| 150 | pass |