chooseLocalOrCachedLibraryPath function
Picks between local and cached paths using the same policy as
lib/src/native_assets/native_library_resolver.dart chooseLocalOrCached.
Implementation
@visibleForTesting
String? chooseLocalOrCachedLibraryPath({
required String? localPath,
required String? cachedPath,
bool preferLocal = false,
DateTime Function(String path)? modifiedAt,
}) {
DateTime mtime(String path) {
if (modifiedAt != null) {
return modifiedAt(path);
}
return File(path).lastModifiedSync();
}
if (preferLocal && localPath != null) {
return localPath;
}
if (localPath != null && cachedPath != null) {
final localTime = mtime(localPath);
final cachedTime = mtime(cachedPath);
if (!localTime.isBefore(cachedTime)) {
return localPath;
}
return cachedPath;
}
return cachedPath ?? localPath;
}