@@ -2,6 +2,7 @@ import 'dart:io';
22
33import 'package:otzaria/attached_libraries/repository/attached_library_registry.dart' ;
44import 'package:otzaria/data/data_providers/book_composite_key.dart' ;
5+ import 'package:otzaria/data/data_providers/db_read_worker.dart' ;
56import 'package:otzaria/data/data_providers/sqlite_data_provider.dart' ;
67import 'package:otzaria/data/data_providers/user_books_database_holder.dart' ;
78import 'package:otzaria/data/official_book_title_renames.dart' ;
@@ -70,13 +71,15 @@ class BookDatabaseResolver {
7071 /// מאתר ספר לפי מאפייניו במסדי הספרייה.
7172 ///
7273 /// [preferSource] נבדק ראשון; [officialOnly] מונע fallback ל-`user_books.db` .
74+ /// [throwIfUnavailable] מדווח על מסד קיים שקריאה ממנו אינה זמינה.
7375 static Future <ResolvedDbBookRecord ?> resolveBook ({
7476 required String title,
7577 int ? categoryId,
7678 String ? fileType,
7779 String ? filePath,
7880 BookSource preferSource = BookSource .official,
7981 bool officialOnly = false ,
82+ bool throwIfUnavailable = false ,
8083 }) async {
8184 final List <ResolvedBookRepositoryCandidate > candidates;
8285 if (officialOnly) {
@@ -93,6 +96,19 @@ class BookDatabaseResolver {
9396 candidates = await _loadRepositoryCandidates (preferSource: preferSource);
9497 }
9598
99+ if (throwIfUnavailable &&
100+ ! preferSource.isAttached &&
101+ SqliteDataProvider .instance.isClosedForExternalWrite) {
102+ throw const DbReadWorkerSuspended ();
103+ }
104+ if (throwIfUnavailable &&
105+ candidates.isEmpty &&
106+ preferSource is AttachedBookSource &&
107+ AttachedLibraryRegistry .instance.libraryFor (preferSource.slug) !=
108+ null ) {
109+ throw StateError ('Cannot read attached library ${preferSource .slug }' );
110+ }
111+
96112 return resolveBookInCandidates (
97113 title: title,
98114 candidates: candidates,
0 commit comments