mirror of
https://github.com/SkinnyMind/libgit2dart.git
synced 2025-05-04 20:29:08 -04:00
use path instead of uri
This commit is contained in:
parent
7141d95cd6
commit
85ea6429eb
2 changed files with 26 additions and 31 deletions
|
@ -8,21 +8,14 @@ import 'package:libgit2dart/src/util.dart';
|
|||
import 'package:path/path.dart' as path;
|
||||
import 'package:pub_cache/pub_cache.dart';
|
||||
|
||||
/// Checks whether libgit2 library is present in directory for [platform].
|
||||
bool libgit2IsPresent(String platform) {
|
||||
final result = File.fromUri(
|
||||
Directory.current.uri.resolve(path.join(libDir, platform, getLibName())),
|
||||
).existsSync();
|
||||
return result;
|
||||
}
|
||||
|
||||
/// Copies prebuilt libgit2 library from package in '.pub_cache' into correct
|
||||
/// directory for [platform].
|
||||
Future<void> copyLibrary(String platform) async {
|
||||
final logger = Logger.standard();
|
||||
final ansi = Ansi(Ansi.terminalSupportsAnsi);
|
||||
|
||||
if (libgit2IsPresent(platform)) {
|
||||
if (File(path.join(Directory.current.path, libDir, platform, getLibName()))
|
||||
.existsSync()) {
|
||||
if (libgit2Version == Libgit2.version) {
|
||||
logger.stdout('${ansi.green}libgit2 for $platform is already available.');
|
||||
} else {
|
||||
|
@ -38,12 +31,13 @@ Future<void> copyLibrary(String platform) async {
|
|||
final pubCacheDir =
|
||||
pubCache.getLatestVersion('libgit2dart')!.resolve()!.location;
|
||||
final libName = getLibName();
|
||||
final libUri = pubCacheDir.uri.resolve(path.join(platform, libName));
|
||||
|
||||
logger.stdout('Copying libgit2 for $platform');
|
||||
final destination = path.join(libDir, platform);
|
||||
Directory(destination).createSync(recursive: true);
|
||||
File.fromUri(libUri).copySync(path.join(destination, libName));
|
||||
File(path.join(pubCacheDir.path, platform, libName)).copySync(
|
||||
path.join(destination, libName),
|
||||
);
|
||||
|
||||
logger.stdout(
|
||||
'${ansi.green}Done! libgit2 for $platform is now available!'
|
||||
|
|
|
@ -26,44 +26,45 @@ String getLibName() {
|
|||
}
|
||||
|
||||
/// Checks if [File]/[Link] exists for an [uri].
|
||||
bool _doesFileExist(Uri uri) {
|
||||
return File.fromUri(uri).existsSync() || Link.fromUri(uri).existsSync();
|
||||
bool _doesFileExist(String path) {
|
||||
return File(path).existsSync() || Link(path).existsSync();
|
||||
}
|
||||
|
||||
/// Returns path to dynamic library if found.
|
||||
String? _resolveLibUri(String name) {
|
||||
var libUri = Directory.current.uri.resolve(name);
|
||||
String? _resolveLibPath(String name) {
|
||||
var libPath = path.join(Directory.current.path, name);
|
||||
|
||||
// If lib is in Present Working Directory.
|
||||
if (_doesFileExist(libUri)) {
|
||||
return libUri.toFilePath(windows: Platform.isWindows);
|
||||
if (_doesFileExist(libPath)) {
|
||||
return libPath;
|
||||
}
|
||||
|
||||
// If lib is in Present Working Directory's '.dart_tool/libgit2/[platform]' folder.
|
||||
final logger = Logger.standard();
|
||||
libUri = Directory.current.uri.resolve(
|
||||
path.join(libDir, Platform.operatingSystem, name),
|
||||
libPath = path.join(
|
||||
Directory.current.path,
|
||||
libDir,
|
||||
Platform.operatingSystem,
|
||||
name,
|
||||
);
|
||||
logger.stdout('$libUri');
|
||||
if (_doesFileExist(libUri)) {
|
||||
return libUri.toFilePath(windows: Platform.isWindows);
|
||||
logger.stdout(libPath);
|
||||
if (_doesFileExist(libPath)) {
|
||||
return libPath;
|
||||
}
|
||||
|
||||
// If lib is in Present Working Directory's '[platform]' folder.
|
||||
libUri = Directory.current.uri.resolve(
|
||||
path.join(Platform.operatingSystem, name),
|
||||
);
|
||||
if (_doesFileExist(libUri)) {
|
||||
return libUri.toFilePath(windows: Platform.isWindows);
|
||||
libPath = path.join(Directory.current.path, Platform.operatingSystem, name);
|
||||
if (_doesFileExist(libPath)) {
|
||||
return libPath;
|
||||
}
|
||||
|
||||
// If lib is in '.pub_cache' folder.
|
||||
final pubCache = PubCache();
|
||||
final pubCacheDir =
|
||||
pubCache.getLatestVersion('libgit2dart')!.resolve()!.location;
|
||||
libUri = pubCacheDir.uri.resolve(path.join(Platform.operatingSystem, name));
|
||||
if (_doesFileExist(libUri)) {
|
||||
return libUri.toFilePath(windows: Platform.isWindows);
|
||||
libPath = path.join(pubCacheDir.path, Platform.operatingSystem, name);
|
||||
if (_doesFileExist(libPath)) {
|
||||
return libPath;
|
||||
}
|
||||
|
||||
return null;
|
||||
|
@ -72,7 +73,7 @@ String? _resolveLibUri(String name) {
|
|||
DynamicLibrary loadLibrary(String name) {
|
||||
try {
|
||||
return DynamicLibrary.open(
|
||||
_resolveLibUri(name) ?? name,
|
||||
_resolveLibPath(name) ?? name,
|
||||
);
|
||||
} catch (e) {
|
||||
final logger = Logger.standard();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue