π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
fix(auth): update coping mechanism
Prateek Sunalcdeb1aa9bca4
diff --git a/auth/lib/utils/directory_utils.dart b/auth/lib/utils/directory_utils.dartindex f7fbfdf606..169f5d2876 100644--- a/auth/lib/utils/directory_utils.dart+++ b/auth/lib/utils/directory_utils.dart@@ -1,5 +1,6 @@import 'dart:io';+import 'package:io/io.dart';import 'package:logging/logging.dart';import 'package:path/path.dart' as p;import 'package:path_provider/path_provider.dart';@@ -12,20 +13,11 @@ class DirectoryUtils {static Future<String> getDatabasePath(String databaseName) async {String? directoryPath;- if (Platform.isLinux) {- try {- directoryPath = dataHome.path;- } catch (e) {- logger.warning("Failed to get dataHome: $e");- }- }-- directoryPath ??= (await getLibraryDirectory()).path;+ directoryPath ??= (await getApplicationSupportDirectory()).path;return p.joinAll([directoryPath,- "enteauth",".$databaseName",],);@@ -52,70 +44,63 @@ class DirectoryUtils {static String migratedNamingChanges = "migrated_naming_changes.b5";static migrateNamingChanges() async {- final sharedPrefs = await SharedPreferences.getInstance();- if (sharedPrefs.containsKey(migratedNamingChanges)) {- return;- }- final databaseFile = File(- p.join(- (await getApplicationDocumentsDirectory()).path,- "ente",- ".ente.authenticator.db",- ),- );- final offlineDatabaseFile = File(- p.join(- (await getApplicationDocumentsDirectory()).path,- "ente",- ".ente.offline_authenticator.db",- ),- );- Directory oldDataDir;- Directory newDataDir;-- if (Platform.isLinux) {- oldDataDir = Directory(- p.join(dataHome.path, "ente_auth"),+ try {+ final sharedPrefs = await SharedPreferences.getInstance();+ if (sharedPrefs.containsKey(migratedNamingChanges)) {+ return;+ }+ final databaseFile = File(+ p.join(+ (await getApplicationDocumentsDirectory()).path,+ "ente",+ ".ente.authenticator.db",+ ),);- } else {- oldDataDir = Directory(+ final offlineDatabaseFile = File(p.join((await getApplicationDocumentsDirectory()).path,"ente",+ ".ente.offline_authenticator.db",),);- }- newDataDir = await getApplicationSupportDirectory();- await newDataDir.create(recursive: true);+ Directory oldDataDir;+ Directory newDataDir;++ if (Platform.isLinux) {+ oldDataDir = Directory(+ p.join(dataHome.path, "ente_auth"),+ );+ } else {+ oldDataDir = Directory(+ p.join(+ (await getApplicationDocumentsDirectory()).path,+ "ente",+ ),+ );+ }+ newDataDir = await getApplicationSupportDirectory();+ await newDataDir.create(recursive: true);- File newDatabaseFile =- File(p.join(newDataDir.path, ".ente.authenticator.db"));- if (await databaseFile.exists() && !await newDatabaseFile.exists()) {- await databaseFile.copy(newDatabaseFile.path);- }+ File newDatabaseFile =+ File(p.join(newDataDir.path, ".ente.authenticator.db"));+ if (await databaseFile.exists() && !await newDatabaseFile.exists()) {+ await databaseFile.copy(newDatabaseFile.path);+ }- File newOfflineDatabaseFile =- File(p.join(newDataDir.path, ".ente.offline_authenticator.db"));- if (await offlineDatabaseFile.exists() &&- !await newOfflineDatabaseFile.exists()) {- await offlineDatabaseFile.copy(newOfflineDatabaseFile.path);- }+ File newOfflineDatabaseFile =+ File(p.join(newDataDir.path, ".ente.offline_authenticator.db"));+ if (await offlineDatabaseFile.exists() &&+ !await newOfflineDatabaseFile.exists()) {+ await offlineDatabaseFile.copy(newOfflineDatabaseFile.path);+ }- if (Platform.isLinux && await oldDataDir.exists()) {- final result = await Process.run(- "cp",- [- "-r",- "${oldDataDir.path}/*",- newDataDir.path,- ],- );- if (result.exitCode != 0) {- logger.warning("Failed to copy old data dir to new data dir");- return;+ if (Platform.isLinux && await oldDataDir.exists()) {+ await copyPath(oldDataDir.path, newDataDir.path);}- }- sharedPrefs.setBool(migratedNamingChanges, true).ignore();+ sharedPrefs.setBool(migratedNamingChanges, true).ignore();+ } catch (e, st) {+ logger.warning("Migrating Database failed!", e, st);+ }}}diff --git a/auth/pubspec.lock b/auth/pubspec.lockindex a2249434e4..08ebc6efbd 100644--- a/auth/pubspec.lock+++ b/auth/pubspec.lock@@ -870,7 +870,7 @@ packages:source: hostedversion: "0.19.0"io:- dependency: transitive+ dependency: "direct main"description:name: iosha256: "2ec25704aba361659e10e3e5f5d672068d332fc8ac516421d483a11e5cbd061e"diff --git a/auth/pubspec.yaml b/auth/pubspec.yamlindex 2e4c6e1107..8d417272a7 100644--- a/auth/pubspec.yaml+++ b/auth/pubspec.yaml@@ -62,6 +62,7 @@ dependencies:gradient_borders: ^1.0.0http: ^1.1.0intl: ^0.19.0+ io: ^1.0.4json_annotation: ^4.5.0local_auth: ^2.3.0local_auth_android: ^1.0.37