@@ -46,8 +46,12 @@ void _initBindings(DynamicLibrary library) {
46
46
}
47
47
48
48
final _couchbaseDartIsLocalPackage = Future .sync (() async {
49
+ final couchbaseDartPackageRootUri = await _couchbaseDartPackageRootUri;
50
+ if (couchbaseDartPackageRootUri == null ) {
51
+ return false ;
52
+ }
49
53
return path
50
- .canonicalize (( await _couchbaseDartPackageRootUri) .toFilePath ())
54
+ .canonicalize (couchbaseDartPackageRootUri .toFilePath ())
51
55
.endsWith ('couchbase-dart/packages/couchbase' );
52
56
});
53
57
@@ -56,7 +60,11 @@ final _couchbaseDartPackageRootUri = Future.sync(() async {
56
60
Uri .parse ('package:couchbase/couchbase.dart' ),
57
61
);
58
62
59
- return File (packageEntryUri! .toFilePath ()).parent.parent.uri;
63
+ if (packageEntryUri == null ) {
64
+ return null ;
65
+ }
66
+
67
+ return File (packageEntryUri.toFilePath ()).parent.parent.uri;
60
68
});
61
69
62
70
String _nativeLibraryBaseName () {
@@ -85,7 +93,7 @@ final _installedNativeLibraryPath =
85
93
86
94
final _localNativeLibraryDirectoryPath = Future .sync (() async {
87
95
final packageRootUri = await _couchbaseDartPackageRootUri;
88
- return path.join (packageRootUri.toFilePath (), '../../native/build' );
96
+ return path.join (packageRootUri! .toFilePath (), '../../native/build' );
89
97
});
90
98
91
99
DynamicLibrary _openNativeLibrary (String directory) =>
@@ -182,12 +190,19 @@ Future<void> _unpackTarArchive(
182
190
}
183
191
}
184
192
185
- await Directory (directory).delete (recursive: true );
186
- await Directory (directory).create (recursive: true );
193
+ await _ensureEmptyDirectory (directory);
187
194
await temporaryDirectory.rename (directory);
188
195
// ignore: avoid_catches_without_on_clauses
189
196
} catch (e) {
190
197
await temporaryDirectory.delete (recursive: true );
191
198
rethrow ;
192
199
}
193
200
}
201
+
202
+ Future <void > _ensureEmptyDirectory (String path) async {
203
+ final directory = Directory (path);
204
+ if (directory.existsSync ()) {
205
+ await directory.delete (recursive: true );
206
+ }
207
+ await directory.create (recursive: true );
208
+ }
0 commit comments