mirror of
https://gitlab.com/nkming2/nc-photos.git
synced 2025-01-22 08:46:18 +01:00
Fix missing files after changing included dirs
This commit is contained in:
parent
651a48efa8
commit
94cb4e7d92
2 changed files with 24 additions and 1 deletions
|
@ -6,6 +6,7 @@ class _Bloc extends Bloc<_Event, _State> with BlocLogger {
|
|||
required Account account,
|
||||
required this.prefController,
|
||||
required this.accountPrefController,
|
||||
required this.npDb,
|
||||
this.highlight,
|
||||
}) : super(_State.init(
|
||||
account: account,
|
||||
|
@ -88,11 +89,11 @@ class _Bloc extends Bloc<_Event, _State> with BlocLogger {
|
|||
|
||||
Future<void> _onSetAccount(_SetAccount ev, Emitter<_State> emit) async {
|
||||
_log.info(ev);
|
||||
final revert = state.account;
|
||||
emit(state.copyWith(
|
||||
account: ev.account,
|
||||
shouldReload: true,
|
||||
));
|
||||
final revert = state.account;
|
||||
try {
|
||||
final accounts = prefController.accountsValue;
|
||||
if (accounts.contains(ev.account)) {
|
||||
|
@ -112,6 +113,20 @@ class _Bloc extends Bloc<_Event, _State> with BlocLogger {
|
|||
_log.severe("[_onSetAccount] Failed while setAccounts3: ${ev.account}");
|
||||
throw const _WritePrefError();
|
||||
}
|
||||
// clear files in db
|
||||
for (final r in {
|
||||
...revert.roots,
|
||||
accountPrefController.shareFolderValue,
|
||||
}) {
|
||||
_log.info("[_onSetAccount] Delete dir: $r");
|
||||
try {
|
||||
final f = File(path: file_util.unstripPath(revert, r));
|
||||
await npDb.truncateDir(account: revert.toDb(), dir: f.toDbKey());
|
||||
await npDb.deleteFile(account: revert.toDb(), file: f.toDbKey());
|
||||
} catch (e, stackTrace) {
|
||||
_log.severe("[_onSetAccount] Failed deleting dir: $r", e, stackTrace);
|
||||
}
|
||||
}
|
||||
} catch (_) {
|
||||
emit(state.copyWith(account: revert));
|
||||
rethrow;
|
||||
|
@ -155,6 +170,7 @@ class _Bloc extends Bloc<_Event, _State> with BlocLogger {
|
|||
final PrefController prefController;
|
||||
final AccountPrefController accountPrefController;
|
||||
final AccountSettingsOption? highlight;
|
||||
final NpDb npDb;
|
||||
|
||||
final _subscriptions = <StreamSubscription>[];
|
||||
var _isHandlingError = false;
|
||||
|
|
|
@ -3,6 +3,7 @@ import 'dart:async';
|
|||
import 'package:copy_with/copy_with.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:kiwi/kiwi.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
import 'package:nc_photos/account.dart';
|
||||
import 'package:nc_photos/app_localizations.dart';
|
||||
|
@ -10,6 +11,10 @@ import 'package:nc_photos/bloc_util.dart';
|
|||
import 'package:nc_photos/controller/account_controller.dart';
|
||||
import 'package:nc_photos/controller/account_pref_controller.dart';
|
||||
import 'package:nc_photos/controller/pref_controller.dart';
|
||||
import 'package:nc_photos/db/entity_converter.dart';
|
||||
import 'package:nc_photos/di_container.dart';
|
||||
import 'package:nc_photos/entity/file.dart';
|
||||
import 'package:nc_photos/entity/file_util.dart' as file_util;
|
||||
import 'package:nc_photos/entity/person.dart';
|
||||
import 'package:nc_photos/exception_event.dart';
|
||||
import 'package:nc_photos/help_utils.dart' as help_util;
|
||||
|
@ -23,6 +28,7 @@ import 'package:nc_photos/widget/settings/settings_list_caption.dart';
|
|||
import 'package:nc_photos/widget/share_folder_picker.dart';
|
||||
import 'package:nc_photos/widget/simple_input_dialog.dart';
|
||||
import 'package:np_codegen/np_codegen.dart';
|
||||
import 'package:np_db/np_db.dart';
|
||||
import 'package:np_ui/np_ui.dart';
|
||||
import 'package:to_string/to_string.dart';
|
||||
|
||||
|
@ -75,6 +81,7 @@ class AccountSettings extends StatelessWidget {
|
|||
account: accountController.account,
|
||||
prefController: context.read(),
|
||||
accountPrefController: accountController.accountPrefController,
|
||||
npDb: KiwiContainer().resolve<DiContainer>().npDb,
|
||||
highlight: highlight,
|
||||
),
|
||||
child: const _WrappedAccountSettings(),
|
||||
|
|
Loading…
Reference in a new issue