(content: str, target_path: str)
| 427 | |
| 428 | |
| 429 | def write_and_fudge_mtime(content: str, target_path: str) -> None: |
| 430 | # In some systems, mtime has a resolution of 1 second which can |
| 431 | # cause annoying-to-debug issues when a file has the same size |
| 432 | # after a change. We manually set the mtime to circumvent this. |
| 433 | # Note that we increment the old file's mtime, which guarantees a |
| 434 | # different value, rather than incrementing the mtime after the |
| 435 | # copy, which could leave the mtime unchanged if the old file had |
| 436 | # a similarly fudged mtime. |
| 437 | new_time = None |
| 438 | if os.path.isfile(target_path): |
| 439 | new_time = os.stat(target_path).st_mtime + 1 |
| 440 | |
| 441 | dir = os.path.dirname(target_path) |
| 442 | os.makedirs(dir, exist_ok=True) |
| 443 | with open(target_path, "w", encoding="utf-8") as target: |
| 444 | target.write(content) |
| 445 | |
| 446 | if new_time: |
| 447 | os.utime(target_path, times=(new_time, new_time)) |
| 448 | |
| 449 | |
| 450 | def perform_file_operations(operations: list[UpdateFile | DeleteFile]) -> None: |
no test coverage detected
searching dependent graphs…