fix: lookup library in Flutter's .pub_cache folder (#66)

This commit is contained in:
Aleksey Kulikov 2022-06-09 17:56:27 +03:00 committed by GitHub
parent 48e2240c73
commit 6be34fe9a0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -6,6 +6,7 @@ import 'dart:io';
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
import 'package:libgit2dart/src/bindings/libgit2_opts_bindings.dart';
import 'package:path/path.dart' as path;
import 'package:pub_cache/pub_cache.dart';
const libgit2Version = '1.4.3';
final libDir = path.join('.dart_tool', 'libgit2');
@ -52,6 +53,21 @@ String? _resolveLibPath(String name) {
libPath = path.join(path.dirname(Platform.resolvedExecutable), 'lib', name);
if (_doesFileExist(libPath)) return libPath;
String checkCache(PubCache pubCache) {
final pubCacheDir =
pubCache.getLatestVersion('libgit2dart')!.resolve()!.location;
return path.join(pubCacheDir.path, Platform.operatingSystem, name);
}
// 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;
}