aboutsummaryrefslogtreecommitdiff
path: root/webmentions_ssg/tasks/scanner.py
diff options
context:
space:
mode:
Diffstat (limited to 'webmentions_ssg/tasks/scanner.py')
-rw-r--r--webmentions_ssg/tasks/scanner.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/webmentions_ssg/tasks/scanner.py b/webmentions_ssg/tasks/scanner.py
index 4bb6736..e8149ba 100644
--- a/webmentions_ssg/tasks/scanner.py
+++ b/webmentions_ssg/tasks/scanner.py
@@ -439,6 +439,10 @@ def scan_sources() -> None:
sa.select(Source).options(selectinload(Source.sent_webmentions))
)
}
+ # Existing sources retain their canonical URLs even when marked deleted.
+ # Reserve these URLs before scanning so an alias cannot claim one just
+ # because it is discovered earlier than its persisted owner.
+ paths_by_url = {source.url: source.path for source in sources_by_path.values()}
seen_paths: set[str] = set()
scanned_count = 0
@@ -470,6 +474,17 @@ def scan_sources() -> None:
)
continue
+ if (owner_path := paths_by_url.get(scanned.url)) is not None and (
+ owner_path != scanned.path
+ ):
+ current_app.logger.warning(
+ "Skipping source %s: duplicate canonical URL %r (already used by %s)",
+ index_path,
+ scanned.url,
+ owner_path,
+ )
+ continue
+
try:
if (source := sources_by_path.get(scanned.path)) is None:
source = create_source(scanned, scan_time)
@@ -478,6 +493,7 @@ def scan_sources() -> None:
source = update_source(source, scanned, scan_time)
sources_by_path[source.path] = source
+ paths_by_url[source.url] = source.path
scanned_count += 1
except SourceScanError as exc:
current_app.logger.warning("Could not scan source %s: %s", index_path, exc)