feat: record files deployed

This commit is contained in:
2 * r + 2 * t
2026-06-17 00:59:54 +10:00
parent 0980986ed4
commit be61b8b072
3 changed files with 22 additions and 4 deletions
+11 -2
View File
@@ -2,10 +2,15 @@ import shutil
import tempfile
from pathlib import Path
from caelestia.utils.paths import dots_dir
class Deployer:
"""Places files from the dots clone into their destinations."""
def __init__(self):
self.deployed_files: dict[str, str] = {}
def place(self, src: Path, dest: Path) -> None:
"""Place a whole entry (file or directory tree), replacing any existing dest."""
@@ -27,7 +32,7 @@ class Deployer:
elif path.is_dir():
(dest / path.relative_to(src)).mkdir(parents=True, exist_ok=True)
def place_file(self, src: Path, dest: Path) -> None:
def place_file(self, src: Path, dest: Path, record: bool = True) -> None:
"""Atomically place a single file, replacing any existing dest."""
if dest.is_dir() and not dest.is_symlink():
@@ -44,11 +49,15 @@ class Deployer:
Path(f.name).unlink()
raise
if record:
# Keep relative to dots dir
self.deployed_files[str(dest)] = str(src.relative_to(dots_dir))
def write_new(self, src: Path, dest: Path) -> Path:
"""Write the upstream version alongside dest as <dest>.new and return that path."""
new_path = dest.parent / f"{dest.name}.new"
self.place_file(src, new_path)
self.place_file(src, new_path, record=False)
return new_path
def remove(self, path: Path) -> None: