mirror of
https://github.com/caelestia-dots/cli.git
synced 2026-06-20 07:50:00 -05:00
feat: record files deployed
This commit is contained in:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user