Skip to content

Commit adc856f

Browse files
committed
db [nfc]: Comment on the use of getApplicationDocumentsDirectory
Signed-off-by: Zixuan James Li <[email protected]>
1 parent 0921eed commit adc856f

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

lib/model/store.dart

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -778,19 +778,22 @@ class LiveGlobalStore extends GlobalStore {
778778

779779
/// The file path to use for the app database.
780780
static Future<File> _dbFile() async {
781-
// What directory should we use?
782-
// path_provider's getApplicationSupportDirectory:
783-
// on Android, -> Flutter's PathUtils.getFilesDir -> https://developer.android.com/reference/android/content/Context#getFilesDir()
784-
// -> empirically /data/data/com.zulip.flutter/files/
785-
// on iOS, -> "Library/Application Support" via https://developer.apple.com/documentation/foundation/nssearchpathdirectory/nsapplicationsupportdirectory
786-
// on Linux, -> "${XDG_DATA_HOME:-~/.local/share}/com.zulip.flutter/"
787-
// All seem reasonable.
788-
// path_provider's getApplicationDocumentsDirectory:
789-
// on Android, -> Flutter's PathUtils.getDataDirectory -> https://developer.android.com/reference/android/content/Context#getDir(java.lang.String,%20int)
790-
// with https://developer.android.com/reference/android/content/Context#MODE_PRIVATE
791-
// on iOS, "Document directory" via https://developer.apple.com/documentation/foundation/nssearchpathdirectory/nsdocumentdirectory
792-
// on Linux, -> `xdg-user-dir DOCUMENTS` -> e.g. ~/Documents
793-
// That Linux answer is definitely not a fit. Harder to tell about the rest.
781+
// path_provider's getApplicationSupportDirectory:
782+
// on Android, -> Flutter's PathUtils.getFilesDir -> https://developer.android.com/reference/android/content/Context#getFilesDir()
783+
// -> empirically /data/data/com.zulip.flutter/files/
784+
// on iOS, -> "Library/Application Support" via https://developer.apple.com/documentation/foundation/nssearchpathdirectory/nsapplicationsupportdirectory
785+
// on Linux, -> "${XDG_DATA_HOME:-~/.local/share}/com.zulip.flutter/"
786+
//
787+
// This is reasonable for iOS per Apple's recommendation:
788+
// > Use ["Library/Application Support"] to store all app data files except
789+
// > those associated with the user’s documents. For example, you might use
790+
// > this directory to store app-created data files, configuration files,
791+
// > templates, or other fixed or modifiable resources that are managed by
792+
// > the app.
793+
// See: https://developer.apple.com/library/archive/documentation/FileManagement/Conceptual/FileSystemProgrammingGuide/FileSystemOverview/FileSystemOverview.html#//apple_ref/doc/uid/TP40010672-CH2-SW2
794+
//
795+
// The paths are reasonable for both Android and Linux, compared to the
796+
// ones from using path_provider's getApplicationDocumentsDirectory.
794797
final dir = await getApplicationSupportDirectory();
795798
return File(p.join(dir.path, 'zulip.db'));
796799
}

0 commit comments

Comments
 (0)