mirror of
https://github.com/SkinnyMind/libgit2dart.git
synced 2025-05-04 20:29:08 -04:00
fix: lookup library in Dart's and Flutter's .pub-cache
This commit is contained in:
parent
d901d2e13f
commit
12ee9f3b53
1 changed files with 19 additions and 15 deletions
|
@ -35,9 +35,7 @@ String? _resolveLibPath(String name) {
|
|||
var libPath = path.join(Directory.current.path, name);
|
||||
|
||||
// If lib is in Present Working Directory.
|
||||
if (_doesFileExist(libPath)) {
|
||||
return libPath;
|
||||
}
|
||||
if (_doesFileExist(libPath)) return libPath;
|
||||
|
||||
// If lib is in Present Working Directory's '.dart_tool/libgit2/[platform]' folder.
|
||||
libPath = path.join(
|
||||
|
@ -46,23 +44,29 @@ String? _resolveLibPath(String name) {
|
|||
Platform.operatingSystem,
|
||||
name,
|
||||
);
|
||||
if (_doesFileExist(libPath)) {
|
||||
return libPath;
|
||||
}
|
||||
if (_doesFileExist(libPath)) return libPath;
|
||||
|
||||
// If lib is in Present Working Directory's '[platform]' folder.
|
||||
libPath = path.join(Directory.current.path, Platform.operatingSystem, name);
|
||||
if (_doesFileExist(libPath)) {
|
||||
return libPath;
|
||||
}
|
||||
if (_doesFileExist(libPath)) return libPath;
|
||||
|
||||
// If lib is in '.pub_cache' folder.
|
||||
final pubCache = PubCache();
|
||||
String checkCache(PubCache pubCache) {
|
||||
final pubCacheDir =
|
||||
pubCache.getLatestVersion('libgit2dart')!.resolve()!.location;
|
||||
libPath = path.join(pubCacheDir.path, Platform.operatingSystem, name);
|
||||
if (_doesFileExist(libPath)) {
|
||||
return libPath;
|
||||
return path.join(pubCacheDir.path, Platform.operatingSystem, name);
|
||||
}
|
||||
|
||||
// If lib is in Dart's '.pub_cache' folder.
|
||||
libPath = checkCache(PubCache());
|
||||
if (_doesFileExist(libPath)) return libPath;
|
||||
|
||||
// If lib is in Flutter's '.pub_cache' folder.
|
||||
final env = Platform.environment;
|
||||
if (env.containsKey('FLUTTER_ROOT')) {
|
||||
final flutterPubCache =
|
||||
PubCache(Directory(path.join(env['FLUTTER_ROOT']!, '.pub-cache')));
|
||||
libPath = checkCache(flutterPubCache);
|
||||
if (_doesFileExist(libPath)) return libPath;
|
||||
}
|
||||
|
||||
return null;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue