You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hive.initFlutter() is using getApplicationDocumentsDirectory which is designed to provide a folder accessible to users and therefor also "common between different apps" (source: "path_provider" package) !
(go to More info section to see the folders depending on the platform)
Other solution: Add a comment to explain the implication of initFlutter without using getApplicationSupportDirectory (but with this solution, most users will use the "default bad choice"...
Because most users should do :
/// Use this for files you don’t want exposed to the user. Your app should not/// use this directory for user data files./// (...)
getApplicationSupportDirectory
/// Path to a directory where the application may place data that is/// user-generated, or that cannot otherwise be recreated by your application./// On iOS, this uses the `NSDocumentDirectory` API. Consider using/// [getApplicationSupportDirectory] instead if the data is not user-generated./// (...)
getApplicationDocumentsDirectory
More Info
Here are where data are stored depending on the function called:
getApplicationDocumentsDirectory:
Windows: C/Users/{username}/Documents/ (User accessible AND files common between apps 👎👎 )
Linux: /home/{user}/ (User accessible AND files common between apps 👎👎 )
Android : /data/user/0/{YourAppName}/app_flutter/ (Not really accessible so I guess it is "ok" & dependent on app 👍)
MacOS (Not tested, but I guess, it is like Linux & Windows 👎👎 )
IOS (Not tested, but from documentation, it is specified we should NOT use this function... 👎 )
Web: Not using this function (👍 )
getApplicationSupportDirectory :
Windows: C:\Users\{user}\AppData\Roaming\{YourAppOrganization}\{YourAppName}/ (Not accessible & dependent on app 👍 )
Linux: /home/{user}/.local/share/{YourAppName]/ (Not accessible & dependent on app 👍 )
Android: /data/user/0/{YourAppName}/files/ (Not accessible & dependent on app 👍)
MacOS (Not tested, but I guess, it is like Linux & Windows 👍 )
IOS (Not tested, but from documentation, it is specified we SHOULD use this function... 👍 )
Web: Not using this function (👍 )
The text was updated successfully, but these errors were encountered:
QuentinCG
changed the title
Hive files exposed to user on (theoricaly all) platforms
Hive files exposed to user on (theoricaly all) platforms and potentially common between different apps
Jul 24, 2022
QuentinCG
changed the title
Hive files exposed to user on (theoricaly all) platforms and potentially common between different apps
Flutter: Hive files exposed to user on (theoricaly all) platforms and potentially common between different apps
Jul 24, 2022
Agreed. There's been some ongoing discussion on it for some time now: #746.
There's a comment in there that you can apparently use Hive.init and pass it whatever directory you'd like since initFlutter effectively calls init anyway. e.g.:
final suppDir =awaitgetApplicationSupportDirectory();
Hive.init(suppDir.path);
I've never used Hive before so hopefully it works well; migration would be another case.
Steps to Reproduce
Do
Hive.initFlutter()
Code sample
Hive.initFlutter() is using
getApplicationDocumentsDirectory
which is designed to provide a folder accessible to users and therefor also "common between different apps" (source: "path_provider" package) !(go to
More info
section to see the folders depending on the platform)Version
How to fix
Use
getApplicationSupportDirectory
instead ofgetApplicationDocumentsDirectory
or at least allow to use completly other folder at https://github.com/hivedb/hive/blob/3b12c31a221f97f5ec86fe20df63515aeedf88f0/hive_flutter/lib/src/hive_extensions.dart#L16Other solution: Add a comment to explain the implication of initFlutter without using getApplicationSupportDirectory (but with this solution, most users will use the "default bad choice"...
Because most users should do :
and not
await Hive.initFlutter();
but is really dirty as it implies we need to rely onpath.join(badDir, goodDir)
to understand what we mean... (this function is not intended this way...) https://github.com/hivedb/hive/blob/3b12c31a221f97f5ec86fe20df63515aeedf88f0/hive_flutter/lib/src/hive_extensions.dart#L17Ressources
path_provider documentation:
More Info
Here are where data are stored depending on the function called:
getApplicationDocumentsDirectory:
C/Users/{username}/Documents/
(User accessible AND files common between apps 👎👎 )/home/{user}/
(User accessible AND files common between apps 👎👎 )/data/user/0/{YourAppName}/app_flutter/
(Not really accessible so I guess it is "ok" & dependent on app 👍)getApplicationSupportDirectory :
C:\Users\{user}\AppData\Roaming\{YourAppOrganization}\{YourAppName}/
(Not accessible & dependent on app 👍 )/home/{user}/.local/share/{YourAppName]/
(Not accessible & dependent on app 👍 )/data/user/0/{YourAppName}/files/
(Not accessible & dependent on app 👍)The text was updated successfully, but these errors were encountered: