π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
fix(auth): use parent directory for iOS security-scoped access
Prateek Sunal10c2e901ef10
diff --git a/mobile/apps/auth/lib/services/local_backup_service.dart b/mobile/apps/auth/lib/services/local_backup_service.dartindex 3f790aa041..4568f0a51c 100644--- a/mobile/apps/auth/lib/services/local_backup_service.dart+++ b/mobile/apps/auth/lib/services/local_backup_service.dart@@ -80,29 +80,33 @@ class LocalBackupService {return true;}- final dir = Directory(target.path!);+ final scopedDir = Directory(target.path!);+ // On iOS, create EnteAuthBackups subdirectory inside the user-selected folder+ final backupDir = Platform.isIOS+ ? Directory('${scopedDir.path}/EnteAuthBackups')+ : scopedDir;// On iOS, we need to access security-scoped resources for directories- // outside the app sandbox (e.g., user-selected folders)+ // outside the app sandbox (e.g., user-selected folders).if (Platform.isIOS) {await SecurityScopedResource.instance- .startAccessingSecurityScopedResource(dir);+ .startAccessingSecurityScopedResource(scopedDir);}try {- await dir.create(recursive: true);- final filePath = '${dir.path}/$fileName';+ await backupDir.create(recursive: true);+ final filePath = '${backupDir.path}/$fileName';final backupFile = File(filePath);await backupFile.create(recursive: true);await backupFile.writeAsString(content);- await _manageOldBackups(dir.path);+ await _manageOldBackups(backupDir.path);_logger.info('Automatic encrypted backup successful! Saved to: $filePath');return true;} finally {if (Platform.isIOS) {await SecurityScopedResource.instance- .stopAccessingSecurityScopedResource(dir);+ .stopAccessingSecurityScopedResource(scopedDir);}}} catch (e, s) {@@ -185,21 +189,24 @@ class LocalBackupService {Future<void> deleteAllBackupsIn(String path) async {try {- final directory = Directory(path);+ final scopedDir = Directory(path);+ // On iOS, backups are in EnteAuthBackups subdirectory+ final backupDir =+ Platform.isIOS ? Directory('$path/EnteAuthBackups') : scopedDir;- // On iOS, we need to access security-scoped resources+ // On iOS, we need to access security-scoped resources.if (Platform.isIOS) {await SecurityScopedResource.instance- .startAccessingSecurityScopedResource(directory);+ .startAccessingSecurityScopedResource(scopedDir);}try {- if (!await directory.exists()) {+ if (!await backupDir.exists()) {_logger.warning('Old backup directory not found. Nothing to delete.');return;}- final files = directory+ final files = backupDir.listSync().where((entity) =>@@ -221,7 +228,7 @@ class LocalBackupService {} finally {if (Platform.isIOS) {await SecurityScopedResource.instance- .stopAccessingSecurityScopedResource(directory);+ .stopAccessingSecurityScopedResource(scopedDir);}}} catch (e, s) {diff --git a/mobile/apps/auth/lib/ui/settings/data/local_backup/local_backup_experience.dart b/mobile/apps/auth/lib/ui/settings/data/local_backup/local_backup_experience.dartindex bca62ee670..18e70eebac 100644--- a/mobile/apps/auth/lib/ui/settings/data/local_backup/local_backup_experience.dart+++ b/mobile/apps/auth/lib/ui/settings/data/local_backup/local_backup_experience.dart@@ -694,17 +694,13 @@ class _LocalBackupExperienceState extends State<LocalBackupExperience> {String path, {String? successMessage,}) async {- // On iOS, create an EnteAuthBackups subdirectory within the selected folder- final targetPath = Platform.isIOS ? '$path/EnteAuthBackups' : path;-final prefs = await SharedPreferences.getInstance();Future<bool> savePath(String target) async {try {// On iOS, we need security-scoped access to the user-selected directory- // before we can create subdirectories in itif (Platform.isIOS) {await SecurityScopedResource.instance- .startAccessingSecurityScopedResource(Directory(path));+ .startAccessingSecurityScopedResource(Directory(target));}try {@@ -724,7 +720,7 @@ class _LocalBackupExperienceState extends State<LocalBackupExperience> {} finally {if (Platform.isIOS) {await SecurityScopedResource.instance- .stopAccessingSecurityScopedResource(Directory(path));+ .stopAccessingSecurityScopedResource(Directory(target));}}} catch (_) {@@ -732,13 +728,13 @@ class _LocalBackupExperienceState extends State<LocalBackupExperience> {}}- if (await savePath(targetPath)) {+ if (await savePath(path)) {return true;}if (Platform.isAndroid) {final fallbackPath = await _androidPrivateBackupPath();- if (fallbackPath != null && fallbackPath != targetPath) {+ if (fallbackPath != null && fallbackPath != path) {final savedFallback = await savePath(fallbackPath);if (savedFallback) {return true;