Hive: FileSystemException: Creation failed

Created on 7 Sep 2019  路  4Comments  路  Source: hivedb/hive

Question
Hi, I wanted to try out Hive in my app, but unfortunately I came across an error when opening a box. The folder "hive" already exists and I use the iOS Simulator.

FileSystemException (FileSystemException: Creation failed, path = 'assets' (OS Error: Permission denied, errno = 13))

Code sample
Hive.init("assets/data/hive/");
await Hive.openBox("game");
var gameBox = Hive.box("game");

Version

  • Platform: iOS
  • Flutter version: 1.7.8
  • Hive version: 0.5.1
    Screenshot 2019-09-07 at 13 37 33
question

Most helpful comment

Thanks for the answer, I implemented it like in your "Todo App" example and got to know path_provider as well. The problem was still there, but "chmod 777" probably solved it.

All 4 comments

I don't think this is a valid path. Since the asset files are read only, Hive cannot create a box there.
Please use the path_provider package to get a valid path. Take a look at the example apps in the Hive repository.

Thanks for the answer, I implemented it like in your "Todo App" example and got to know path_provider as well. The problem was still there, but "chmod 777" probably solved it.

Solved with: getApplicationDocumentsDirectory()

@leisim I'm getting this same error after running the project again for some time.

FileSystemException: Cannot create file, path = /Users/thinkdigital/Library/Developer/CoreSimulator/Devices/F3A5BA32-2FC7-491B-9862-A42B54C487A5/data/Containers/Data/Application/7B94FC78-4946-497E-9953-E25E7B4FCE1F/Documents/FullPackage
Exception:
    message: Cannot create file
    path: /users/thinkdigital/library/developer/coresimulator/devices/f3a5ba32-2fc7-491b-9862- 
        a42b54c487a5/data/containers/data/application/7b94fc78-4946-497e-9953- 
        e25e7b4fce1f/documents/fullpackage.hive
    OS Error: No such file or directory, errno = 2

Sorry for the bad formatting. I tried deleting the app from the simulator, I also tried ensuring that the path existed by CD'ing there from the terminal and it does.

The code in question is

  Future initialize() async {
    var applicationsDocumentDirectory =
        await getApplicationDocumentsDirectory();
    var hiveBoxPath =
        '${applicationsDocumentDirectory.path}/${ValueType.toString()}';
    box = await Hive.openBox(hiveBoxPath);
  }

Another weird thing is that hiveBoxPath evaluates to
/Users/thinkdigital/Library/Developer/CoreSimulator/Devices/F3A5BA32-2FC7-491B-9862-A42B54C487A5/data/Containers/Data/Application/7B94FC78-4946-497E-9953-E25E7B4FCE1F/Documents/FullPackage, which is the same as the path in the error message, but with the proper capitals and it's missing the '.hive' extension.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kaboc picture kaboc  路  3Comments

MyoLinOo picture MyoLinOo  路  3Comments

SergeShkurko picture SergeShkurko  路  4Comments

kthecoder picture kthecoder  路  3Comments

cachapa picture cachapa  路  4Comments