2021-04-10 06:28:12 +02:00
|
|
|
import 'package:logging/logging.dart';
|
|
|
|
import 'package:nc_photos/account.dart';
|
2021-09-04 14:35:04 +02:00
|
|
|
import 'package:nc_photos/debug_util.dart';
|
2021-04-10 06:28:12 +02:00
|
|
|
import 'package:nc_photos/entity/file.dart';
|
2021-12-19 19:09:38 +01:00
|
|
|
import 'package:nc_photos/entity/file_util.dart' as file_util;
|
2021-04-30 17:25:15 +02:00
|
|
|
import 'package:nc_photos/exception.dart';
|
2021-10-26 16:44:33 +02:00
|
|
|
import 'package:nc_photos/exception_event.dart';
|
2021-05-23 19:22:22 +02:00
|
|
|
import 'package:nc_photos/remote_storage_util.dart' as remote_storage_util;
|
2021-04-10 06:28:12 +02:00
|
|
|
import 'package:nc_photos/use_case/ls.dart';
|
2022-12-16 16:01:04 +01:00
|
|
|
import 'package:np_codegen/np_codegen.dart';
|
2021-04-10 06:28:12 +02:00
|
|
|
|
2022-12-16 16:01:04 +01:00
|
|
|
part 'scan_dir.g.dart';
|
|
|
|
|
|
|
|
@npLog
|
2021-04-10 06:28:12 +02:00
|
|
|
class ScanDir {
|
|
|
|
ScanDir(this.fileRepo);
|
|
|
|
|
|
|
|
/// List all files under a dir recursively
|
2022-01-19 06:08:48 +01:00
|
|
|
Stream<dynamic> call(Account account, File root) async* {
|
2021-04-10 06:28:12 +02:00
|
|
|
try {
|
|
|
|
final items = await Ls(fileRepo)(account, root);
|
2021-12-19 19:09:38 +01:00
|
|
|
yield items
|
2022-01-19 06:08:48 +01:00
|
|
|
.where(
|
|
|
|
(f) => f.isCollection != true && file_util.isSupportedFormat(f))
|
2021-12-19 19:09:38 +01:00
|
|
|
.toList();
|
2021-05-23 19:22:22 +02:00
|
|
|
for (final i in items.where((element) =>
|
|
|
|
element.isCollection == true &&
|
|
|
|
!element.path
|
|
|
|
.endsWith(remote_storage_util.getRemoteStorageDir(account)))) {
|
2021-04-10 06:28:12 +02:00
|
|
|
yield* this(account, i);
|
|
|
|
}
|
2021-10-26 16:44:33 +02:00
|
|
|
} on CacheNotFoundException catch (e, stackTrace) {
|
2021-04-30 17:25:15 +02:00
|
|
|
_log.info("[call] Cache not found");
|
2021-10-26 16:44:33 +02:00
|
|
|
yield ExceptionEvent(e, stackTrace);
|
|
|
|
} catch (e, stackTrace) {
|
2021-12-02 09:27:11 +01:00
|
|
|
_log.shout("[call] Failed while listing dir: ${logFilename(root.path)}",
|
|
|
|
e, stackTrace);
|
2021-04-10 06:28:12 +02:00
|
|
|
// for some reason exception thrown here can't be caught outside
|
|
|
|
// rethrow;
|
2021-10-26 16:44:33 +02:00
|
|
|
yield ExceptionEvent(e, stackTrace);
|
2021-04-10 06:28:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
final FileRepo fileRepo;
|
|
|
|
}
|