@@ -18,25 +18,11 @@ import 'package:meta/meta.dart';
1818
1919/// Storage backend for the Dart VM
2020class StorageBackendVm extends StorageBackend {
21- /// Warning for existing lock of unmatched isolation
22- @visibleForTesting
23- static const unmatchedIsolationWarning = '''
24- ⚠️ WARNING: HIVE MULTI-ISOLATE RISK DETECTED ⚠️
25-
26- You are opening this box with Hive, but this box was previously opened with
27- IsolatedHive. This can lead to DATA CORRUPTION as Hive boxes are not designed
28- for concurrent access across isolates. Each isolate would maintain its own box
29- cache, potentially causing data inconsistency and corruption.
30-
31- RECOMMENDED ACTIONS:
32- - ALWAYS use IsolatedHive to perform box operations when working with multiple
33- isolates
34- ''' ;
35-
3621 final File _file;
3722 final File _lockFile;
3823 final bool _crashRecovery;
3924 final HiveCipher ? _cipher;
25+ final int ? _keyCrc;
4026 final FrameIoHelper _frameHelper;
4127
4228 final ReadWriteSync _sync;
@@ -73,6 +59,7 @@ RECOMMENDED ACTIONS:
7359 this ._lockFile,
7460 this ._crashRecovery,
7561 this ._cipher,
62+ this ._keyCrc,
7663 ) : _frameHelper = FrameIoHelper (),
7764 _sync = ReadWriteSync ();
7865
@@ -82,6 +69,7 @@ RECOMMENDED ACTIONS:
8269 this ._lockFile,
8370 this ._crashRecovery,
8471 this ._cipher,
72+ this ._keyCrc,
8573 this ._frameHelper,
8674 this ._sync,
8775 );
@@ -116,7 +104,7 @@ RECOMMENDED ACTIONS:
116104 props = LockProps ();
117105 }
118106 if (Logger .unmatchedIsolationWarning && props.isolated && ! isolated) {
119- Logger .w (unmatchedIsolationWarning );
107+ Logger .w (HiveWarning .unmatchedIsolation );
120108 }
121109 }
122110
@@ -132,10 +120,12 @@ RECOMMENDED ACTIONS:
132120 keystore,
133121 registry,
134122 _cipher,
123+ _keyCrc,
135124 verbatim: isolated,
136125 );
137126 } else {
138- recoveryOffset = await _frameHelper.keysFromFile (path, keystore, _cipher);
127+ recoveryOffset =
128+ await _frameHelper.keysFromFile (path, keystore, _cipher, _keyCrc);
139129 }
140130
141131 if (recoveryOffset != - 1 ) {
@@ -158,8 +148,12 @@ RECOMMENDED ACTIONS:
158148 final bytes = await readRaf.read (frame.length! );
159149
160150 final reader = BinaryReaderImpl (bytes, registry);
161- final readFrame =
162- reader.readFrame (cipher: _cipher, lazy: false , verbatim: verbatim);
151+ final readFrame = reader.readFrame (
152+ cipher: _cipher,
153+ keyCrc: _keyCrc,
154+ lazy: false ,
155+ verbatim: verbatim,
156+ );
163157
164158 if (readFrame == null ) {
165159 throw HiveError (
@@ -177,8 +171,12 @@ RECOMMENDED ACTIONS:
177171 final writer = BinaryWriterImpl (registry);
178172
179173 for (final frame in frames) {
180- frame.length =
181- writer.writeFrame (frame, cipher: _cipher, verbatim: verbatim);
174+ frame.length = writer.writeFrame (
175+ frame,
176+ cipher: _cipher,
177+ keyCrc: _keyCrc,
178+ verbatim: verbatim,
179+ );
182180 }
183181
184182 try {
0 commit comments