Skip to content
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

FileSystemException: Cannot create file, path = '//testbox.hive' (OS Error: Read-only file system, errno = 30) #656

Closed
good-good-study opened this issue May 8, 2021 · 6 comments
Labels
question Further information is requested

Comments

@good-good-study
Copy link

good-good-study commented May 8, 2021

Flutter Hive version:2.0.4, I download the Demo hivedb/hive , found abnormal after running :

Syncing files to device iPhone 12 Pro Max...
Restarted application in 840ms.

[VERBOSE-2:ui_dart_state.cc(199)] Unhandled Exception: FileSystemException: Cannot create file, path = '//testbox.hive' (OS Error: Read-only file system, errno = 30)
#0      _File.create.<anonymous closure> (dart:io/file_impl.dart:255:9)
#1      _rootRunUnary (dart:async/zone.dart:1362:47)
#2      _CustomZone.runUnary (dart:async/zone.dart:1265:19)
<asynchronous suspension>
#3      BackendManager.findHiveFileAndCleanUp (package:hive/src/backend/vm/backend_manager.dart:47:7)
<asynchronous suspension>
#4      BackendManager.open (package:hive/src/backend/vm/backend_manager.dart:24:16)
<asynchronous suspension>
#5      HiveImpl._openBox (package:hive/src/hive_impl.dart:100:15)
<asynchronous suspension>
#6      HiveImpl.openBox (package:hive/src/hive_impl.dart:139:12)
<asynchronous suspension>
#7      main (package:example/main.dart:32:13)
<asynchronous suspension>
[VERBOSE-2:ui_dart_state.cc(199)] Unhandled Exception: FileSystemException: Cannot create file, path = '//testbox.hive' (OS Error: Read-only file system, errno = 30)
#0      _File.create.<anonymous closure> (dart:io/file_impl.dart:255:9)
#1      _rootRunUnary (dart:async/zone.dart:1362:47)
#2      _CustomZone.runUnary (dart:async/zone.dart:1265:19)
<asynchronous suspension>
#3      BackendManager.findHiveFileAndCleanUp (package:hive/src/backend/vm/backend_manager.dart:47:7)
<asynchronous suspension>
#4      BackendManager.open (package:hive/src/backend/vm/backend_manager.dart:24:16)
<asynchronous suspension>
#5      HiveImpl._openBox (package:hive/src/hive_impl.dart:100:15)
<asynchronous suspension>
#6      HiveImpl.openBox (package:hive/src/hive_impl.dart:139:12)
<asynchronous suspension>
#7      main (package:example/main.dart:32:13)
<asynchronous suspension>
@good-good-study good-good-study added the question Further information is requested label May 8, 2021
@themisir
Copy link
Contributor

The example project inside hive/example is a simple dart application not flutter. You can simply run it using dart main.dart.

@bueltan
Copy link

bueltan commented Jul 9, 2021

I have to admit I feel a bit silly now, haha

@aneesshameed
Copy link

For Flutter use

final directory = await getApplicationDocumentsDirectory();
await Hive.initFlutter(directory.path);

Of course, you need to
import 'package:path_provider/path_provider.dart';

@Adminixtrator
Copy link

Adminixtrator commented Dec 28, 2021

For Flutter use

final directory = await getApplicationDocumentsDirectory();
await Hive.initFlutter(directory.path);

Of course, you need to import 'package:path_provider/path_provider.dart';

I made some modifications and this does it.

WidgetsFlutterBinding.ensureInitialized();
final directory = await getApplicationDocumentsDirectory();
Hive.init(directory.path);

@gronka
Copy link

gronka commented Mar 12, 2022

To fix this error, I had to uninstall my flutter app from the Android device, then reinstall with flutter run

@chaudharydeepanshu
Copy link

For me, it was due to forgetting to provide the path when opening the database which was used when initializing Hive.

  Future openDb() async {
    Directory directory = await getApplicationDocumentsDirectory();        //<-----
    collection = await BoxCollection.open(
      'Collection',
      {'Box'},
      path: directory.path,  //<-----
    );
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

7 participants