diff --git a/app/lib/entity/sqlite_table_extension.dart b/app/lib/entity/sqlite_table_extension.dart index 0210c45e..ef25f4ae 100644 --- a/app/lib/entity/sqlite_table_extension.dart +++ b/app/lib/entity/sqlite_table_extension.dart @@ -593,6 +593,9 @@ enum FilesQueryMode { expression, } +typedef FilesQueryRelativePathBuilder = Expression Function( + GeneratedColumn relativePath); + /// Build a Files table query /// /// If you call more than one by* methods, the condition will be added up @@ -646,8 +649,12 @@ class FilesQueryBuilder { _byRelativePath = path; } + void byOrRelativePath(String path) { + _byOrRelativePathBuilder((relativePath) => relativePath.equals(path)); + } + void byOrRelativePathPattern(String pattern) { - (_byOrRelativePathPatterns ??= []).add(pattern); + _byOrRelativePathBuilder((relativePath) => relativePath.like(pattern)); } void byMimePattern(String pattern) { @@ -723,13 +730,13 @@ class FilesQueryBuilder { if (_byRelativePath != null) { query.where(db.accountFiles.relativePath.equals(_byRelativePath)); } - if (_byOrRelativePathPatterns?.isNotEmpty == true) { - final expression = _byOrRelativePathPatterns! + if (_byOrRelativePathBuilders?.isNotEmpty == true) { + final expression = _byOrRelativePathBuilders! .sublist(1) .fold>( - db.accountFiles.relativePath.like(_byOrRelativePathPatterns![0]), - (previousValue, element) => - previousValue | db.accountFiles.relativePath.like(element)); + _byOrRelativePathBuilders![0](db.accountFiles.relativePath), + (previousValue, builder) => + previousValue | builder(db.accountFiles.relativePath)); query.where(expression); } if (_byMimePatterns?.isNotEmpty == true) { @@ -770,6 +777,10 @@ class FilesQueryBuilder { return query; } + void _byOrRelativePathBuilder(FilesQueryRelativePathBuilder builder) { + (_byOrRelativePathBuilders ??= []).add(builder); + } + final SqliteDb db; FilesQueryMode _queryMode = FilesQueryMode.file; @@ -783,7 +794,7 @@ class FilesQueryBuilder { int? _byFileId; Iterable? _byFileIds; String? _byRelativePath; - List? _byOrRelativePathPatterns; + List? _byOrRelativePathBuilders; List? _byMimePatterns; bool? _byFavorite; int? _byDirRowId; diff --git a/app/lib/use_case/sync_dir.dart b/app/lib/use_case/sync_dir.dart index 250eaaa7..8645a33a 100644 --- a/app/lib/use_case/sync_dir.dart +++ b/app/lib/use_case/sync_dir.dart @@ -27,7 +27,7 @@ class SyncDir { String dirPath, { bool isRecursive = true, }) async { - final dirCache = await _queryAllSubDirEtags(account, dirPath); + final dirCache = await _queryAllDirEtags(account, dirPath); final remoteRoot = await LsSingleFile(_c.withRemoteFileRepo())(account, dirPath); return await _syncDir(account, remoteRoot, dirCache, @@ -81,7 +81,7 @@ class SyncDir { return Tuple2(true, touchResult); } - Future> _queryAllSubDirEtags( + Future> _queryAllDirEtags( Account account, String dirPath) async { final dir = File(path: dirPath); return await _c.sqliteDb.use((db) async { @@ -91,7 +91,9 @@ class SyncDir { expressions: [db.files.fileId, db.files.etag]) ..setAppAccount(account); if (dir.strippedPathWithEmpty.isNotEmpty) { - q.byOrRelativePathPattern("${dir.strippedPathWithEmpty}/%"); + q + ..byOrRelativePath(dir.strippedPathWithEmpty) + ..byOrRelativePathPattern("${dir.strippedPathWithEmpty}/%"); } return q.build(); });