resolveArtifact method
Resolve primary and companion paths for a downloaded model artifact.
Implementation
ModelPathResolution? resolveArtifact(ModelInfo model) {
final artifactRoot = model.localPath.isNotEmpty
? model.localPath
: getModelFolder(model.id, model.framework);
if (artifactRoot == null || artifactRoot.isEmpty) return null;
try {
final lib = PlatformLoader.loadCommons();
final resolveFn = lib
.lookupFunction<
Int32 Function(
Pointer<RacModelInfoCStruct>,
Pointer<Utf8>,
Pointer<Utf8>,
Pointer<RacModelPathResolutionStruct>,
),
int Function(
Pointer<RacModelInfoCStruct>,
Pointer<Utf8>,
Pointer<Utf8>,
Pointer<RacModelPathResolutionStruct>,
)
>('rac_model_paths_resolve_artifact');
final freeResolutionFn = lib
.lookupFunction<
Void Function(Pointer<RacModelPathResolutionStruct>),
void Function(Pointer<RacModelPathResolutionStruct>)
>('rac_model_path_resolution_free');
return _withCModelInfo(model, (modelPtr) {
final rootPtr = artifactRoot.toNativeUtf8();
final checksumPtr = model.checksumSha256.isEmpty
? nullptr
: model.checksumSha256.toNativeUtf8();
final resolutionPtr = calloc<RacModelPathResolutionStruct>();
try {
final result = resolveFn(
modelPtr,
rootPtr,
checksumPtr,
resolutionPtr,
);
if (result != RacResultCode.success) {
_logger.debug(
'rac_model_paths_resolve_artifact failed: '
'code=$result model=${model.id}',
);
return null;
}
return _copyResolution(resolutionPtr.ref);
} finally {
freeResolutionFn(resolutionPtr);
calloc.free(rootPtr);
if (checksumPtr != nullptr) {
calloc.free(checksumPtr);
}
calloc.free(resolutionPtr);
}
});
} catch (e) {
_logger.debug('rac_model_paths_resolve_artifact error: $e');
return null;
}
}