Skip to content

Commit 70d2ab4

Browse files
committed
fix: support downloading native binaries with compiled executable
1 parent 8d1a826 commit 70d2ab4

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

packages/couchbase/lib/src/native_library.dart

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,12 @@ void _initBindings(DynamicLibrary library) {
4646
}
4747

4848
final _couchbaseDartIsLocalPackage = Future.sync(() async {
49+
final couchbaseDartPackageRootUri = await _couchbaseDartPackageRootUri;
50+
if (couchbaseDartPackageRootUri == null) {
51+
return false;
52+
}
4953
return path
50-
.canonicalize((await _couchbaseDartPackageRootUri).toFilePath())
54+
.canonicalize(couchbaseDartPackageRootUri.toFilePath())
5155
.endsWith('couchbase-dart/packages/couchbase');
5256
});
5357

@@ -56,7 +60,11 @@ final _couchbaseDartPackageRootUri = Future.sync(() async {
5660
Uri.parse('package:couchbase/couchbase.dart'),
5761
);
5862

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;
6068
});
6169

6270
String _nativeLibraryBaseName() {
@@ -85,7 +93,7 @@ final _installedNativeLibraryPath =
8593

8694
final _localNativeLibraryDirectoryPath = Future.sync(() async {
8795
final packageRootUri = await _couchbaseDartPackageRootUri;
88-
return path.join(packageRootUri.toFilePath(), '../../native/build');
96+
return path.join(packageRootUri!.toFilePath(), '../../native/build');
8997
});
9098

9199
DynamicLibrary _openNativeLibrary(String directory) =>
@@ -182,12 +190,19 @@ Future<void> _unpackTarArchive(
182190
}
183191
}
184192

185-
await Directory(directory).delete(recursive: true);
186-
await Directory(directory).create(recursive: true);
193+
await _ensureEmptyDirectory(directory);
187194
await temporaryDirectory.rename(directory);
188195
// ignore: avoid_catches_without_on_clauses
189196
} catch (e) {
190197
await temporaryDirectory.delete(recursive: true);
191198
rethrow;
192199
}
193200
}
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

Comments
 (0)