Restore index-only snapshot output links

This commit is contained in:
Nick Sweeting
2026-03-15 04:58:46 -07:00
parent cc3e72b92f
commit c4d30a853f
2 changed files with 31 additions and 0 deletions

View File

@@ -120,6 +120,7 @@ def add(urls: str | list[str],
)
if tag:
snapshot.save_tags(tag.split(','))
snapshot.ensure_crawl_symlink()
return crawl.snapshot_set.all()
# 5. Start the orchestrator to process the queue

View File

@@ -384,6 +384,7 @@ class Snapshot(ModelWithOutputDir, ModelWithConfig, ModelWithNotes, ModelWithHea
self.fs_version = target
super().save(*args, **kwargs)
self.ensure_legacy_archive_symlink()
if self.url not in self.crawl.urls:
self.crawl.urls += f'\n{self.url}'
self.crawl.save()
@@ -1362,6 +1363,35 @@ class Snapshot(ModelWithOutputDir, ModelWithConfig, ModelWithNotes, ModelWithHea
return str(current_path)
def ensure_legacy_archive_symlink(self) -> None:
"""Ensure the legacy archive/<timestamp> path resolves to this snapshot."""
import os
legacy_path = CONSTANTS.ARCHIVE_DIR / self.timestamp
target = Path(self.get_storage_path_for_version(self._fs_current_version()))
if target == legacy_path:
return
legacy_path.parent.mkdir(parents=True, exist_ok=True)
if legacy_path.exists() or legacy_path.is_symlink():
if legacy_path.is_symlink():
try:
if legacy_path.resolve() == target.resolve():
return
except OSError:
pass
legacy_path.unlink(missing_ok=True)
else:
return
rel_target = os.path.relpath(target, legacy_path.parent)
try:
legacy_path.symlink_to(rel_target, target_is_directory=True)
except OSError:
return
def ensure_crawl_symlink(self) -> None:
"""Ensure snapshot is symlinked under its crawl output directory."""
import os