From cb2021de74224c97d3b125a7712cec5275baed60 Mon Sep 17 00:00:00 2001 From: Feichtmeier Date: Tue, 1 Oct 2024 22:11:07 +0200 Subject: [PATCH] fix: The presence of a lost+found folder makes musicpod unable to load the users music library Ref #934 --- lib/local_audio/local_audio_service.dart | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/lib/local_audio/local_audio_service.dart b/lib/local_audio/local_audio_service.dart index f72934970..1a60397a2 100644 --- a/lib/local_audio/local_audio_service.dart +++ b/lib/local_audio/local_audio_service.dart @@ -252,15 +252,18 @@ FutureOr _readAudiosFromDirectory(String? directory) async { List failedImports = []; if (directory != null && Directory(directory).existsSync()) { - for (var e in Directory(directory) - .listSync(recursive: true, followLinks: false) - .whereType() - .where((e) => e.isValidMedia) - .toList()) { + final entities = await Directory(directory) + .list(recursive: true, followLinks: false) + .handleError((e) => failedImports.add(e)) + .toList(); + + for (final e in entities) { try { - final metadata = await readMetadata(e, getImage: false); - newAudios.add(Audio.fromMetadata(path: e.path, data: metadata)); - } catch (error) { + if (e is File && e.isValidMedia) { + final metadata = await readMetadata(e, getImage: false); + newAudios.add(Audio.fromMetadata(path: e.path, data: metadata)); + } + } on Exception catch (_) { failedImports.add(e.path); } }