Skip to content

Commit

Permalink
Verify paths when exporting models
Browse files Browse the repository at this point in the history
Verify paths when exporting models to ensure everything is exported into
a subdirectory of the export directory.
  • Loading branch information
amisevsk committed Feb 21, 2024
1 parent a3d377f commit fc00a26
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions pkg/cmd/export/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"jmm/pkg/lib/repo"
"os"
"path"
"path/filepath"

ocispec "github.com/opencontainers/image-spec/specs-go/v1"
"oras.land/oras-go/v2"
Expand Down Expand Up @@ -40,40 +41,40 @@ func ExportModel(ctx context.Context, store oras.Target, ref *registry.Reference
// through the config's relevant field to get the correct path for exporting
var modelIdx, codeIdx, datasetIdx int
for _, layerDesc := range manifest.Layers {
var layerExportErr error
layerDir := ""
switch layerDesc.MediaType {
case constants.ModelLayerMediaType:
if !options.exportConf.ExportModels {
continue
}
modelEntry := config.Models[modelIdx]
layerDir := path.Join(options.exportDir, modelEntry.Path)
layerDir = filepath.Join(options.exportDir, modelEntry.Path)
fmt.Printf("Exporting model %s to %s\n", modelEntry.Name, layerDir)
layerExportErr = ExportLayer(ctx, store, layerDesc, layerDir, options.overwrite)
modelIdx += 1

case constants.CodeLayerMediaType:
if !options.exportConf.ExportCode {
continue
}
codeEntry := config.Code[codeIdx]
layerDir := path.Join(options.exportDir, codeEntry.Path)
layerDir = filepath.Join(options.exportDir, codeEntry.Path)
fmt.Printf("Exporting code to %s\n", layerDir)
layerExportErr = ExportLayer(ctx, store, layerDesc, layerDir, options.overwrite)
codeIdx += 1

case constants.DataSetLayerMediaType:
if !options.exportConf.ExportDatasets {
continue
}
datasetEntry := config.DataSets[datasetIdx]
layerDir := path.Join(options.exportDir, datasetEntry.Path)
layerDir = filepath.Join(options.exportDir, datasetEntry.Path)
fmt.Printf("Exporting dataset %s to %s\n", datasetEntry.Name, layerDir)
layerExportErr = ExportLayer(ctx, store, layerDesc, layerDir, options.overwrite)
datasetIdx += 1
}
if layerExportErr != nil {
return layerExportErr
if _, err := filesystem.VerifySubpath(options.exportDir, layerDir); err != nil {
return err
}
if err := ExportLayer(ctx, store, layerDesc, layerDir, options.overwrite); err != nil {
return err
}
}

Expand Down

0 comments on commit fc00a26

Please sign in to comment.