mirror of
https://gitlab.com/nkming2/nc-photos.git
synced 2025-03-04 22:38:51 +01:00
Fix SyncDir always consider root dirs as changed
This commit is contained in:
parent
62716f3f72
commit
9759f172db
2 changed files with 23 additions and 10 deletions
|
@ -593,6 +593,9 @@ enum FilesQueryMode {
|
|||
expression,
|
||||
}
|
||||
|
||||
typedef FilesQueryRelativePathBuilder = Expression<bool?> Function(
|
||||
GeneratedColumn<String?> 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<Expression<bool?>>(
|
||||
db.accountFiles.relativePath.like(_byOrRelativePathPatterns![0]),
|
||||
(previousValue, element) =>
|
||||
previousValue | db.accountFiles.relativePath.like(element));
|
||||
_byOrRelativePathBuilders,
|
||||
(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<int>? _byFileIds;
|
||||
String? _byRelativePath;
|
||||
List<String>? _byOrRelativePathPatterns;
|
||||
List<FilesQueryRelativePathBuilder>? _byOrRelativePathBuilders;
|
||||
List<String>? _byMimePatterns;
|
||||
bool? _byFavorite;
|
||||
int? _byDirRowId;
|
||||
|
|
|
@ -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<Map<int, String>> _queryAllSubDirEtags(
|
||||
Future<Map<int, String>> _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();
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue