Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Merge remote-tracking branch 'origin/main' into free_up_space_crashing

ashilkn7219d3186261
diff --cc mobile/apps/photos/lib/ui/tools/free_space_page.dart
index 181cbc8526,0328a537cf..364ad03ee4
--- a/mobile/apps/photos/lib/ui/tools/free_space_page.dart
+++ b/mobile/apps/photos/lib/ui/tools/free_space_page.dart
@@@ -5,10 -6,7 +6,9 @@@ import "package:ente_strings/ente_strin
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
import 'package:logging/logging.dart';
- import "package:photos/generated/l10n.dart";
import 'package:photos/models/freeable_space_info.dart';
+import "package:photos/services/files_service.dart";
+import "package:photos/services/free_space/deletion_batch_runner.dart";
import "package:photos/ui/notification/toast.dart";
import 'package:photos/utils/delete_file_util.dart';
@@@ -108,62 -102,29 +108,62 @@@ class _FreeSpacePageState extends State
}
Future<void> _freeStorage(FreeableSpaceInfo status) async {
- bool isSuccess = await deleteLocalFiles(context, status.localIDs);
-
- if (isSuccess == false) {
- if (!mounted) return;
- isSuccess = await deleteLocalFilesAfterRemovingAlreadyDeletedIDs(
- context,
- status.localIDs,
- );
+ if (_isFreeSpaceDeletionInProgress) {
+ return;
}
-
- if (isSuccess == false && Platform.isAndroid) {
- if (!mounted) return;
- isSuccess = await retryFreeUpSpaceAfterRemovingAssetsNonExistingInDisk(
- context,
- );
+ _isFreeSpaceDeletionInProgress = true;
+ if (mounted) {
+ setState(() => _isFreeingSpace = true);
}
- if (isSuccess) {
+ try {
+ late final Set<String> currentLocalIDs;
+ try {
+ final refreshedStatus = await FilesService.instance
+ .getFreeableSpaceInfo();
+ currentLocalIDs = retainOriginalDeletionCandidates(
+ refreshedLocalIDs: refreshedStatus.localIDs,
+ originalLocalIDs: status.localIDs,
+ );
+ } catch (e, s) {
+ _logger.severe("Could not refresh free-up-space candidates", e, s);
+ if (mounted) {
- showToast(context, AppLocalizations.of(context).couldNotFreeUpSpace);
++ showToast(context, context.strings.couldNotFreeUpSpace);
+ }
+ return;
+ }
+
if (!mounted) return;
- Navigator.of(context).pop(true);
- } else {
+ final currentLocalIDList = currentLocalIDs.toList();
+ var result = await deleteLocalFiles(context, currentLocalIDList);
+
+ if (result.shouldTryNextFallback) {
+ if (!mounted) return;
+ result = await deleteLocalFilesAfterRemovingAlreadyDeletedIDs(
+ context,
+ currentLocalIDList,
+ );
+ }
+
+ if (result.shouldTryNextFallback && Platform.isAndroid) {
+ if (!mounted) return;
+ result = await retryFreeUpSpaceAfterRemovingAssetsNonExistingInDisk(
+ context,
+ originalLocalIDs: currentLocalIDs,
+ );
+ }
+
if (!mounted) return;
- showToast(context, context.strings.couldNotFreeUpSpace);
+ if (result.isCompleted) {
+ Navigator.of(context).pop(true);
+ } else if (!result.isCancelled) {
- showToast(context, AppLocalizations.of(context).couldNotFreeUpSpace);
++ showToast(context, context.strings.couldNotFreeUpSpace);
+ }
+ } finally {
+ _isFreeSpaceDeletionInProgress = false;
+ if (mounted) {
+ setState(() => _isFreeingSpace = false);
+ }
}
}
diff --cc mobile/apps/photos/lib/utils/delete_file_util.dart
index 7c2f07d1da,b888a55e95..445e7eac53
--- a/mobile/apps/photos/lib/utils/delete_file_util.dart
+++ b/mobile/apps/photos/lib/utils/delete_file_util.dart
@@@ -522,12 -548,8 +521,12 @@@ retryFreeUpSpaceAfterRemovingAssetsNonE
final dialog = createProgressDialog(
context,
- context.l10n.pleaseWaitThisWillTakeAWhile,
+ context.strings.pleaseWaitThisWillTakeAWhile,
);
+ final localAssetIDs = <String>[];
+ final localSharedMediaIDs = <String>[];
+ late LocalDeletionResult sharedMediaResult;
+
await dialog.show();
try {
final stopwatch = Stopwatch()..start();