Write content to path only if it differs from what's there.
(path: str, content: str)
| 157 | |
| 158 | |
| 159 | def _write_if_changed(path: str, content: str) -> bool: |
| 160 | """Write content to path only if it differs from what's there.""" |
| 161 | try: |
| 162 | with open(path) as f: |
| 163 | if f.read() == content: |
| 164 | return False |
| 165 | except FileNotFoundError: |
| 166 | pass |
| 167 | with open(path, "w") as f: |
| 168 | f.write(content) |
| 169 | return True |
| 170 | |
| 171 | |
| 172 | def _tail_file(path: str, n_bytes: int = 4096) -> str: |
no test coverage detected
searching dependent graphs…