@@ -175,7 +175,13 @@ func hasLayerWithMediaType(model types.Model, targetMediaType oci.MediaType) boo
175175 }
176176}
177177
178- func unpackRuntimeConfig (bundle * Bundle , mdl types.Model ) error {
178+ // configProvider is an interface for types that provide a Config() method.
179+ // Both types.Model and types.ModelArtifact satisfy this interface.
180+ type configProvider interface {
181+ Config () (types.ModelConfig , error )
182+ }
183+
184+ func unpackRuntimeConfig (bundle * Bundle , mdl configProvider ) error {
179185 cfg , err := mdl .Config ()
180186 if err != nil {
181187 return err
@@ -317,11 +323,8 @@ func unpackSafetensorsWithAnnotations(bundle *Bundle, modelDir string, safetenso
317323 digestHex := filepath .Base (srcPath )
318324
319325 var destRelPath string
320- if annotatedPath , ok := blobToFilepath [digestHex ]; ok && strings .Contains (annotatedPath , "/" ) {
321- // Use the annotated path (contains subdirectory)
322- destRelPath = annotatedPath
323- } else if annotatedPath , ok := blobToFilepath [digestHex ]; ok {
324- // Annotation exists but is just a filename - use it
326+ if annotatedPath , ok := blobToFilepath [digestHex ]; ok {
327+ // Use the annotated path
325328 destRelPath = annotatedPath
326329 } else {
327330 // No annotation found - use legacy naming
@@ -422,7 +425,6 @@ func unpackDirTarArchives(bundle *Bundle, mdl types.Model) error {
422425 for _ , layer := range layers {
423426 mediaType , err := layer .MediaType ()
424427 if err != nil {
425- fmt .Printf ("Warning: failed to get media type for layer: %v" , err )
426428 continue
427429 }
428430
@@ -641,21 +643,18 @@ func UnpackFromLayers(dir string, model types.ModelArtifact) (*Bundle, error) {
641643 for _ , layer := range layers {
642644 mediaType , err := layer .MediaType ()
643645 if err != nil {
644- fmt .Printf ("Warning: error getting media type: %v\n " , err )
645646 continue
646647 }
647648
648649 // Get the filepath annotation
649650 dp , ok := layer .(descriptorProvider )
650651 if ! ok {
651- fmt .Printf ("Warning: layer is not a descriptorProvider\n " )
652652 continue
653653 }
654654
655655 desc := dp .GetDescriptor ()
656656 relPath , exists := desc .Annotations [types .AnnotationFilePath ]
657657 if ! exists || relPath == "" {
658- fmt .Printf ("Warning: layer missing filepath annotation\n " )
659658 continue
660659 }
661660
@@ -687,28 +686,16 @@ func UnpackFromLayers(dir string, model types.ModelArtifact) (*Bundle, error) {
687686 updateBundleFieldsFromLayer (bundle , mediaType , relPath )
688687 }
689688
690- // Create the runtime config from the model
691- cfg , err := model .Config ()
692- if err != nil {
693- return nil , fmt .Errorf ("get model config: %w" , err )
694- }
695-
696- // Write runtime config to bundle root
697- f , err := os .Create (filepath .Join (bundle .dir , "config.json" ))
698- if err != nil {
699- return nil , fmt .Errorf ("create runtime config file: %w" , err )
700- }
701- defer f .Close ()
702- if err := json .NewEncoder (f ).Encode (cfg ); err != nil {
703- return nil , fmt .Errorf ("encode runtime config: %w" , err )
689+ // Create the runtime config
690+ if err := unpackRuntimeConfig (bundle , model ); err != nil {
691+ return nil , fmt .Errorf ("add config.json to runtime bundle: %w" , err )
704692 }
705- bundle .runtimeConfig = cfg
706693
707694 return bundle , nil
708695}
709696
710- // unpackLayerToFile unpacks a single layer to the destination path.
711- // It tries to use hard linking for local layers, falling back to copying for remote layers .
697+ // unpackLayerToFile unpacks a single layer to the destination path using hard linking .
698+ // It requires the layer to be a local layer with a file path (pathProvider interface) .
712699func unpackLayerToFile (destPath string , layer oci.Layer ) error {
713700 // Try to get the layer's local path for hard linking
714701 type pathProvider interface {
@@ -724,6 +711,7 @@ func unpackLayerToFile(destPath string, layer oci.Layer) error {
724711
725712// updateBundleFieldsFromLayer updates the bundle tracking fields based on the unpacked layer.
726713func updateBundleFieldsFromLayer (bundle * Bundle , mediaType oci.MediaType , relPath string ) {
714+ //nolint:exhaustive // only tracking specific model-related media types
727715 switch mediaType {
728716 case types .MediaTypeGGUF :
729717 if bundle .ggufFile == "" {
0 commit comments