feat: harden dedupe runtime and NAS deployment
This commit is contained in:
+14
-5
@@ -8,17 +8,20 @@ from watchdog.observers import Observer
|
||||
|
||||
from .constants import MUSIC_EXTENSIONS, STABILITY_CHECKS, STABILITY_INTERVAL_SECONDS
|
||||
from .db import connect
|
||||
from .exact import exact_dedupe
|
||||
from .l2 import acoustic_dedupe
|
||||
from .scanner import index_file
|
||||
|
||||
|
||||
class Handler(FileSystemEventHandler):
|
||||
def __init__(self, root: Path, db_path: Path):
|
||||
def __init__(self, root: Path, db_path: Path, l2: bool = False):
|
||||
self.root = root
|
||||
self.db_path = db_path
|
||||
self.l2 = l2
|
||||
|
||||
def _process(self, filename: str) -> None:
|
||||
path = Path(filename)
|
||||
if path.is_symlink() or path.suffix.lower() not in MUSIC_EXTENSIONS:
|
||||
if path.is_symlink() or path.suffix.lower() not in MUSIC_EXTENSIONS or ".dedupe" in path.parts:
|
||||
return
|
||||
try:
|
||||
previous = path.stat().st_size
|
||||
@@ -33,7 +36,11 @@ class Handler(FileSystemEventHandler):
|
||||
stable = 0
|
||||
with connect(self.db_path) as conn:
|
||||
index_file(conn, path)
|
||||
except (FileNotFoundError, PermissionError):
|
||||
# Exact dedupe is byte-for-byte safe. Acoustic dedupe is opt-in.
|
||||
exact_dedupe(self.db_path, self.root)
|
||||
if self.l2:
|
||||
acoustic_dedupe(self.db_path, self.root)
|
||||
except (FileNotFoundError, PermissionError, OSError):
|
||||
return
|
||||
|
||||
def on_created(self, event):
|
||||
@@ -45,9 +52,11 @@ class Handler(FileSystemEventHandler):
|
||||
self._process(event.dest_path)
|
||||
|
||||
|
||||
def watch(root: Path, db_path: Path) -> None:
|
||||
|
||||
def watch(root: Path, db_path: Path, l2: bool = False) -> None:
|
||||
root = root.resolve()
|
||||
observer = Observer()
|
||||
observer.schedule(Handler(root, db_path), str(root), recursive=True)
|
||||
observer.schedule(Handler(root, db_path, l2=l2), str(root), recursive=True)
|
||||
observer.start()
|
||||
try:
|
||||
while True:
|
||||
|
||||
Reference in New Issue
Block a user