From 368a6a6755860d512f99a02fd9991437a69c37ec Mon Sep 17 00:00:00 2001 From: Ming Ming Date: Fri, 16 Jul 2021 17:25:01 +0800 Subject: [PATCH] Filter out invalid files --- lib/entity/file/data_source.dart | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/lib/entity/file/data_source.dart b/lib/entity/file/data_source.dart index bb01debf..5f88643d 100644 --- a/lib/entity/file/data_source.dart +++ b/lib/entity/file/data_source.dart @@ -60,7 +60,7 @@ class FileWebdavDataSource implements FileDataSource { final xml = XmlDocument.parse(response.body); final files = WebdavFileParser()(xml); // _log.fine("[list] Parsed files: [$files]"); - return files.map((e) { + return files.where((element) => _validateFile(element)).map((e) { if (e.metadata == null || e.metadata.fileEtag == e.etag) { return e; } else { @@ -328,10 +328,14 @@ class FileAppDbDataSource implements FileDataSource { if (results?.isNotEmpty == true) { final entries = results .map((e) => AppDbFileEntry.fromJson(e.cast())); - return entries.map((e) { - _log.info("[_doList] ${e.path}[${e.index}]"); - return e.data; - }).reduce((value, element) => value + element); + return entries + .map((e) { + _log.info("[_doList] ${e.path}[${e.index}]"); + return e.data; + }) + .reduce((value, element) => value + element) + .where((element) => _validateFile(element)) + .toList(); } else { throw CacheNotFoundException("No entry: $path"); } @@ -720,4 +724,9 @@ Future _cacheListResults( } } +bool _validateFile(File f) { + // See: https://gitlab.com/nkming2/nc-photos/-/issues/9 + return f.lastModified != null; +} + final _log = Logger("entity.file.data_source");