@@ -12,6 +12,7 @@ import (
12
12
"jmm/pkg/lib/repo"
13
13
"os"
14
14
"path"
15
+ "path/filepath"
15
16
16
17
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
17
18
"oras.land/oras-go/v2"
@@ -40,40 +41,40 @@ func ExportModel(ctx context.Context, store oras.Target, ref *registry.Reference
40
41
// through the config's relevant field to get the correct path for exporting
41
42
var modelIdx , codeIdx , datasetIdx int
42
43
for _ , layerDesc := range manifest .Layers {
43
- var layerExportErr error
44
+ layerDir := ""
44
45
switch layerDesc .MediaType {
45
46
case constants .ModelLayerMediaType :
46
47
if ! options .exportConf .ExportModels {
47
48
continue
48
49
}
49
50
modelEntry := config .Models [modelIdx ]
50
- layerDir := path .Join (options .exportDir , modelEntry .Path )
51
+ layerDir = filepath .Join (options .exportDir , modelEntry .Path )
51
52
fmt .Printf ("Exporting model %s to %s\n " , modelEntry .Name , layerDir )
52
- layerExportErr = ExportLayer (ctx , store , layerDesc , layerDir , options .overwrite )
53
53
modelIdx += 1
54
54
55
55
case constants .CodeLayerMediaType :
56
56
if ! options .exportConf .ExportCode {
57
57
continue
58
58
}
59
59
codeEntry := config .Code [codeIdx ]
60
- layerDir := path .Join (options .exportDir , codeEntry .Path )
60
+ layerDir = filepath .Join (options .exportDir , codeEntry .Path )
61
61
fmt .Printf ("Exporting code to %s\n " , layerDir )
62
- layerExportErr = ExportLayer (ctx , store , layerDesc , layerDir , options .overwrite )
63
62
codeIdx += 1
64
63
65
64
case constants .DataSetLayerMediaType :
66
65
if ! options .exportConf .ExportDatasets {
67
66
continue
68
67
}
69
68
datasetEntry := config .DataSets [datasetIdx ]
70
- layerDir := path .Join (options .exportDir , datasetEntry .Path )
69
+ layerDir = filepath .Join (options .exportDir , datasetEntry .Path )
71
70
fmt .Printf ("Exporting dataset %s to %s\n " , datasetEntry .Name , layerDir )
72
- layerExportErr = ExportLayer (ctx , store , layerDesc , layerDir , options .overwrite )
73
71
datasetIdx += 1
74
72
}
75
- if layerExportErr != nil {
76
- return layerExportErr
73
+ if _ , err := filesystem .VerifySubpath (options .exportDir , layerDir ); err != nil {
74
+ return err
75
+ }
76
+ if err := ExportLayer (ctx , store , layerDesc , layerDir , options .overwrite ); err != nil {
77
+ return err
77
78
}
78
79
}
79
80
0 commit comments