Add broken symlink diagnostics
This commit is contained in:
@@ -1,14 +1,23 @@
|
||||
from pathlib import Path
|
||||
|
||||
from serato_doctor.models.filesystem import BrokenSymlink, FilesystemScan
|
||||
from serato_doctor.models.track import DiskTrack
|
||||
|
||||
AUDIO_SUFFIXES = {".mp3", ".m4a", ".wav", ".aif", ".aiff", ".flac"}
|
||||
|
||||
|
||||
def scan_audio(folder: Path) -> list[DiskTrack]:
|
||||
def scan_filesystem(folder: Path) -> FilesystemScan:
|
||||
tracks = []
|
||||
broken_symlinks = []
|
||||
|
||||
for path in folder.rglob("*"):
|
||||
if path.is_symlink() and not path.exists():
|
||||
try:
|
||||
target = path.readlink()
|
||||
except OSError:
|
||||
target = None
|
||||
broken_symlinks.append(BrokenSymlink(path=path, target=target))
|
||||
continue
|
||||
if not path.is_file():
|
||||
continue
|
||||
if path.suffix.lower() not in AUDIO_SUFFIXES:
|
||||
@@ -28,4 +37,13 @@ def scan_audio(folder: Path) -> list[DiskTrack]:
|
||||
)
|
||||
)
|
||||
|
||||
return tracks
|
||||
return FilesystemScan(
|
||||
tracks=tuple(tracks),
|
||||
broken_symlinks=tuple(broken_symlinks),
|
||||
)
|
||||
|
||||
|
||||
def scan_audio(folder: Path) -> list[DiskTrack]:
|
||||
"""Scan audio files while preserving the prototype API."""
|
||||
|
||||
return list(scan_filesystem(folder).tracks)
|
||||
|
||||
Reference in New Issue
Block a user