feat: bootstrap NAS music deduper
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
from pathlib import Path
|
||||
|
||||
from am_deduper.db import connect
|
||||
from am_deduper.exact import exact_dedupe
|
||||
from am_deduper.scanner import scan
|
||||
|
||||
|
||||
def test_exact_dedupe_creates_hardlink(tmp_path: Path):
|
||||
root = tmp_path / "AllMusic"
|
||||
(root / "admin").mkdir(parents=True)
|
||||
(root / "alice").mkdir(parents=True)
|
||||
a = root / "admin" / "song.flac"
|
||||
b = root / "alice" / "song.flac"
|
||||
data = b"fake flac content" * 10000
|
||||
a.write_bytes(data)
|
||||
b.write_bytes(data)
|
||||
db = root / ".dedupe" / "dedupe.db"
|
||||
assert scan(root, db) == 2
|
||||
actions = exact_dedupe(db, root)
|
||||
assert len(actions) == 1
|
||||
assert a.stat().st_ino == b.stat().st_ino
|
||||
assert a.read_bytes() == b.read_bytes()
|
||||
@@ -0,0 +1,21 @@
|
||||
from pathlib import Path
|
||||
|
||||
from am_deduper.hashing import fast_hash, sha256
|
||||
|
||||
|
||||
def test_fast_hash_same_content(tmp_path: Path):
|
||||
a = tmp_path / "a.bin"
|
||||
b = tmp_path / "b.bin"
|
||||
data = b"x" * 200_000
|
||||
a.write_bytes(data)
|
||||
b.write_bytes(data)
|
||||
assert fast_hash(a) == fast_hash(b)
|
||||
assert sha256(a) == sha256(b)
|
||||
|
||||
|
||||
def test_fast_hash_uses_size(tmp_path: Path):
|
||||
a = tmp_path / "a.bin"
|
||||
b = tmp_path / "b.bin"
|
||||
a.write_bytes(b"x" * 100)
|
||||
b.write_bytes(b"x" * 101)
|
||||
assert fast_hash(a) != fast_hash(b)
|
||||
Reference in New Issue
Block a user