fix: close Walloon terrain provisioning
This commit is contained in:
@@ -32,6 +32,17 @@ def sha256_file(path: Path) -> str:
|
||||
return digest.hexdigest()
|
||||
|
||||
|
||||
def write_text_atomic(path: Path, content: str, *, encoding: str) -> None:
|
||||
temporary = path.with_suffix(path.suffix + ".part")
|
||||
temporary.unlink(missing_ok=True)
|
||||
try:
|
||||
temporary.write_text(content, encoding=encoding)
|
||||
temporary.replace(path)
|
||||
except Exception:
|
||||
temporary.unlink(missing_ok=True)
|
||||
raise
|
||||
|
||||
|
||||
def download(destination: Path) -> str:
|
||||
temporary = destination.with_suffix(destination.suffix + ".part")
|
||||
temporary.unlink(missing_ok=True)
|
||||
@@ -202,8 +213,10 @@ def provision(destination: Path, force: bool, keep_archive: bool) -> dict:
|
||||
archive.unlink(missing_ok=True)
|
||||
validation = validate_raster(target)
|
||||
source_digest = sha256_file(target)
|
||||
target.with_suffix(".sha256").write_text(
|
||||
f"{source_digest} {target.name}\n", encoding="ascii"
|
||||
write_text_atomic(
|
||||
target.with_suffix(".sha256"),
|
||||
f"{source_digest} {target.name}\n",
|
||||
encoding="ascii",
|
||||
)
|
||||
validation.update(
|
||||
{
|
||||
@@ -214,7 +227,11 @@ def provision(destination: Path, force: bool, keep_archive: bool) -> dict:
|
||||
}
|
||||
)
|
||||
report_path = destination / "provisioning-report.json"
|
||||
report_path.write_text(json.dumps(validation, indent=2) + "\n", encoding="utf-8")
|
||||
write_text_atomic(
|
||||
report_path,
|
||||
json.dumps(validation, indent=2) + "\n",
|
||||
encoding="utf-8",
|
||||
)
|
||||
print(f"SPW MNT: ready ({target.stat().st_size / 1024 / 1024 / 1024:.1f} GiB)")
|
||||
print(f"Provisioning report: {report_path}")
|
||||
return validation
|
||||
|
||||
Reference in New Issue
Block a user