fix: stop calling a held file its own duplicate

This commit is contained in:
Abdessamad Derraz committed 2026-10-18 08:41:32 +02:00
1 parent fd6db086d3
commit 7bd2579022
2 files changed
+24 -3

No files matched your search

+13 -3
View File
@@ -210,9 +210,19 @@ def validate_file(
if db:
if result.sha1 in db.get("files", {}):
existing = db["files"][result.sha1]
result.add_warning(
f"Duplicate: identical file already exists at `{existing['path']}`"
)
held_at = {
os.path.normpath(p)
for p in [existing.get("path"), *(existing.get("paths") or [])] if p
}
if os.path.normpath(filepath) in held_at:
# The file the database was built from, not a copy of it: a
# PR that regenerated database.json was told each new file
# duplicated itself.
result.add_check(True, "Already in the database at this path")
else:
result.add_warning(
f"Duplicate: identical file already exists at `{existing['path']}`"
)
else:
result.add_check(True, "Not a duplicate in database")
+11
View File
@@ -184,6 +184,17 @@ class HashRecognition(_Fixture):
self.assertTrue(validate_pr.validate_file(rel, db, EMPTY_HASHES).passed)
def test_the_file_the_database_holds_is_not_its_own_duplicate(self):
"""The documented example on a tracked file warned "Duplicate:
identical file already exists at" the very path being validated."""
rel = self._bios_file("bios/Sony/PS/held.bin")
probe = validate_pr.validate_file(rel, None, EMPTY_HASHES)
db = {"files": {probe.sha1: {"path": rel}}}
markdown = validate_pr.validate_file(rel, db, EMPTY_HASHES).to_markdown()
self.assertNotIn("Duplicate", markdown)
self.assertIn("Already in the database at this path", markdown)
class Placement(_Fixture):
def test_manufacturer_and_console_directories_are_accepted(self):
rel = self._bios_file("bios/Sega/Saturn/sega_101.bin")