Skip to content

Commit

Permalink
db [nfc]: Comment on the use of getApplicationDocumentsDirectory
Browse files Browse the repository at this point in the history
Signed-off-by: Zixuan James Li <[email protected]>
  • Loading branch information
PIG208 committed Dec 16, 2024
1 parent cbffbf2 commit 75a93be
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions lib/model/store.dart
Original file line number Diff line number Diff line change
Expand Up @@ -778,19 +778,22 @@ class LiveGlobalStore extends GlobalStore {

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

0 comments on commit 75a93be

Please sign in to comment.