mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-12-02 06:18:51 -06:00
fix: dedup walks only the files the scan indexes
This commit is contained in:
1 parent
f896893b6e
commit
64db75a6ee
5 files changed
+51
-31
No files matched your search
@@ -7,6 +7,7 @@ from collections import defaultdict
|
||||
from pathlib import Path
|
||||
|
||||
from collection.scan import primary_rank
|
||||
from core.collectionfiles import collection_files
|
||||
from core.hashing import compute_hashes
|
||||
from model.nodedup import in_nodedup_dir
|
||||
|
||||
@@ -18,7 +19,10 @@ def _is_mame_dir(path: str) -> bool:
|
||||
|
||||
|
||||
def scan_duplicates(bios_dir: str) -> dict[str, list[str]]:
|
||||
"""Files grouped by SHA1, excluding no-dedup directories.
|
||||
"""Collection files grouped by SHA1, excluding no-dedup directories.
|
||||
|
||||
The walk is the database scan's: a copy the index never sees (under
|
||||
`.cache/`, a hidden file) is no candidate to keep or to remove.
|
||||
|
||||
Two equal files have the same size, so only files that share a size are
|
||||
read, and for the sha1 alone: hashing the whole tree with every digest
|
||||
@@ -26,12 +30,12 @@ def scan_duplicates(bios_dir: str) -> dict[str, list[str]]:
|
||||
size is in no group of two and is left out.
|
||||
"""
|
||||
by_size: dict[int, list[str]] = defaultdict(list)
|
||||
for root, _dirs, files in os.walk(bios_dir):
|
||||
for name in files:
|
||||
path = os.path.join(root, name)
|
||||
if in_nodedup_dir(path):
|
||||
continue
|
||||
by_size[os.path.getsize(path)].append(path)
|
||||
root = Path(bios_dir)
|
||||
for found in collection_files(root):
|
||||
path = os.path.join(bios_dir, found.relative_to(root))
|
||||
if in_nodedup_dir(path):
|
||||
continue
|
||||
by_size[os.path.getsize(path)].append(path)
|
||||
|
||||
sha1_to_paths: dict[str, list[str]] = defaultdict(list)
|
||||
for paths in by_size.values():
|
||||
|
||||
@@ -1,15 +1,14 @@
|
||||
"""The walk of bios/: which files count, their digests, and which copy of a content is primary."""
|
||||
"""The walk of bios/: each collection file's digests, and which copy of a content is primary."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
from core.collectionfiles import collection_files
|
||||
from core.hashing import compute_hashes
|
||||
from resolve.localfile import variant_base_name
|
||||
|
||||
SKIP_PATTERNS = {".git", ".github", "__pycache__", ".cache", ".DS_Store", "desktop.ini"}
|
||||
|
||||
# Every digest database.json publishes per file, in the order compute_hashes
|
||||
# returns them. The schema requires all five, so a cache entry missing any of
|
||||
# them cannot serve a database entry, and the order is fixed here so a warm
|
||||
@@ -17,18 +16,6 @@ SKIP_PATTERNS = {".git", ".github", "__pycache__", ".cache", ".DS_Store", "deskt
|
||||
CACHED_HASHES = ("sha1", "md5", "sha256", "crc32", "adler32")
|
||||
|
||||
|
||||
def should_skip(path: Path) -> bool:
|
||||
"""Whether a path stays out of the collection.
|
||||
|
||||
Tooling directories and hidden files do. A hidden directory inside the
|
||||
collection does not: `.variants/` holds alternate dumps, and an engine
|
||||
tree can carry one of its own (C-Dogs SDL reads `data/.wolf3d/`).
|
||||
"""
|
||||
if any(part in SKIP_PATTERNS for part in path.parts):
|
||||
return True
|
||||
return path.name.startswith(".")
|
||||
|
||||
|
||||
def _canonical_name(filepath: Path) -> str:
|
||||
"""Get canonical filename, stripping .variants/ hash suffix."""
|
||||
if ".variants" in filepath.parts:
|
||||
@@ -135,12 +122,7 @@ def scan_bios_dir(bios_dir: Path, cache: dict, force: bool) -> tuple[dict, dict,
|
||||
new_cache = {}
|
||||
root = Path(bios_dir.name)
|
||||
|
||||
for filepath in sorted(bios_dir.rglob("*")):
|
||||
if not filepath.is_file():
|
||||
continue
|
||||
if should_skip(filepath.relative_to(bios_dir)):
|
||||
continue
|
||||
|
||||
for filepath in collection_files(bios_dir):
|
||||
rel_path = str(filepath.relative_to(bios_dir.parent))
|
||||
stat = filepath.stat()
|
||||
mtime = stat.st_mtime
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
"""Which files under bios/ belong to the collection."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Iterator
|
||||
from pathlib import Path
|
||||
|
||||
SKIP_PATTERNS = {".git", ".github", "__pycache__", ".cache", ".DS_Store", "desktop.ini"}
|
||||
|
||||
|
||||
def should_skip(path: Path) -> bool:
|
||||
"""Whether a path stays out of the collection.
|
||||
|
||||
Tooling directories and hidden files do. A hidden directory inside the
|
||||
collection does not: `.variants/` holds alternate dumps, and an engine
|
||||
tree can carry one of its own (C-Dogs SDL reads `data/.wolf3d/`).
|
||||
"""
|
||||
if any(part in SKIP_PATTERNS for part in path.parts):
|
||||
return True
|
||||
return path.name.startswith(".")
|
||||
|
||||
|
||||
def collection_files(bios_dir: Path) -> Iterator[Path]:
|
||||
"""Every file of the collection under *bios_dir*, in walk order.
|
||||
|
||||
The database scan and the dedup both read this walk. The dedup walked
|
||||
every file and ranked a copy under `bios/.cache/` with the others: it
|
||||
could keep that copy, which no index names, and delete the indexed one.
|
||||
"""
|
||||
for path in sorted(bios_dir.rglob("*")):
|
||||
if path.is_file() and not should_skip(path.relative_to(bios_dir)):
|
||||
yield path
|
||||
Reference in new issue
Block a user