-
Notifications
You must be signed in to change notification settings - Fork 57
Replaced getApplicationDocumentsDirectory() with getApplicationSupportDirectory in io.dart #181
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
06d06da
bddb860
f78df86
b88cf8e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -10,19 +10,28 @@ import 'package:path_provider/path_provider.dart'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| class StoreImpl with Store { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| final bool storageJson; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| StoreImpl({this.storageJson = true}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| late final Future<void> _migrationCompleted; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| StoreImpl({this.storageJson = true}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Start migration immediately but don't block construction | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| _migrationCompleted = _migrateFilesFromDocumentsToSupport(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @override | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Future get ready => Future.value(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @override | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Future<Map<String, dynamic>?> getPersisted(String key) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Future<Map<String, dynamic>?> getPersisted(String key) async { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!storageJson) return Future.value(null); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Ensure migration is complete before reading files | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| await _migrationCompleted; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return _readFile(key); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @override | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Future get ready => Future.value(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @override | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Future setPersisted(String key, Map<String, dynamic> value) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Future setPersisted(String key, Map<String, dynamic> value) async { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!storageJson) return Future.value(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Ensure migration is complete before writing files | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| await _migrationCompleted; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return _writeFile(key, value); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -70,7 +79,7 @@ class StoreImpl with Store { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Future<String> _fileName(String fileKey) async { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| final path = (await _getDocumentDir()).path; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| final path = (await _getNewDocumentDir()).path; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return "$path/analytics-flutter-$fileKey.json"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -88,14 +97,60 @@ class StoreImpl with Store { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Future<Directory> _getDocumentDir() async { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Future<Directory> _getNewDocumentDir() async { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return await getApplicationSupportDirectory(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return await getApplicationSupportDirectory(); | |
| final newDir = await getApplicationSupportDirectory(); | |
| final oldDir = await getApplicationDocumentsDirectory(); | |
| // Migrate old files if they exist | |
| final oldFiles = oldDir | |
| .listSync() | |
| .whereType<File>() | |
| .where((file) => file.path.contains('analytics-flutter-') && file.path.endsWith('.json')); | |
| for (final oldFile in oldFiles) { | |
| final fileName = oldFile.uri.pathSegments.last; | |
| final newFile = File('${newDir.path}/$fileName'); | |
| if (!await newFile.exists()) { | |
| await oldFile.copy(newFile.path); | |
| await oldFile.delete(); | |
| } | |
| } | |
| return newDir; |
neelkanth-kaushik marked this conversation as resolved.
Show resolved
Hide resolved
Copilot
AI
Sep 23, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The catch block silently ignores all exceptions during file operations. Consider logging the error for debugging purposes while still allowing the app to continue.
| } catch (e) { | |
| // The app should continue to work even if migration fails | |
| } | |
| } | |
| } | |
| } catch (e) { | |
| // Migration failure shouldn't break the app | |
| } catch (e, stackTrace) { | |
| // The app should continue to work even if migration fails | |
| print('File migration error: \$e'); | |
| print(stackTrace); | |
| } | |
| } | |
| } | |
| } catch (e, stackTrace) { | |
| // Migration failure shouldn't break the app | |
| print('Migration failure: \$e'); | |
| print(stackTrace); |
Copilot
AI
Sep 23, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The catch block silently ignores all exceptions during migration. Consider logging the error for debugging purposes while still allowing the app to continue.
| // The app should continue to work even if migration fails | |
| } | |
| } | |
| } | |
| } catch (e) { | |
| // Migration failure shouldn't break the app | |
| // The app should continue to work even if migration fails | |
| print('Error migrating file ${oldFile.path} to $newFilePath: $e'); | |
| } | |
| } | |
| } | |
| } catch (e) { | |
| // Migration failure shouldn't break the app | |
| print('Error during migration from Documents to Support directory: $e'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we add the writekey to the new doc path here?
Not sure if we can only just hope there's no cross-contamination with multiple writekeys in one app so far...
@bsneed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, we should.