From 16088428f4d44cfe2d0257d3bdd3304c4c5a1199 Mon Sep 17 00:00:00 2001 From: Uwe Krueger Date: Thu, 10 Nov 2022 09:05:36 +0100 Subject: [PATCH] fix omitted dest option for artifact download --- .../ocicmds/artefacts/download/cmd.go | 25 ++++++++++++++----- .../v3alpha1/jsonscheme/bindata.go | 2 +- .../versions/v2/jsonscheme/bindata.go | 2 +- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/cmds/ocm/commands/ocicmds/artefacts/download/cmd.go b/cmds/ocm/commands/ocicmds/artefacts/download/cmd.go index 60bd465e8..d65b1cbd5 100644 --- a/cmds/ocm/commands/ocicmds/artefacts/download/cmd.go +++ b/cmds/ocm/commands/ocicmds/artefacts/download/cmd.go @@ -5,9 +5,9 @@ package download import ( - "path" "strings" + "github.com/mandelsoft/vfs/pkg/vfs" "github.com/spf13/cobra" "github.com/open-component-model/ocm/cmds/ocm/commands/common/options/destoption" @@ -106,12 +106,15 @@ func (d *download) Out() error { out.Outf(d.opts.Context, "no artefacts found\n") } if len(d.data) == 1 { - return d.Save(d.data[0], dest.Destination) + f := dest.Destination + e := d.data[0] + if f == "" { + f = composePath(dest, e) + } + return d.Save(e, f) } else { for _, e := range d.data { - f := e.Spec.UniformRepositorySpec.String() - f = strings.ReplaceAll(f, "::", "-") - f = path.Join(f, e.Spec.Repository) + f := composePath(dest, e) err := d.Save(e, f) if err != nil { list.Add(err) @@ -122,10 +125,20 @@ func (d *download) Out() error { return list.Result() } +func composePath(dest *destoption.Option, e *artefacthdlr.Object) string { + f := e.Spec.UniformRepositorySpec.String() + f = strings.ReplaceAll(f, "::", "-") + f = vfs.Join(dest.PathFilesystem, f, e.Spec.Repository) + if dest.Destination != "" { + return vfs.Join(dest.PathFilesystem, dest.Destination, f) + } + return f +} + func (d *download) Save(o *artefacthdlr.Object, f string) error { dest := destoption.From(d.opts) art := o.Artefact - dir := path.Dir(f) + dir := vfs.Dir(dest.PathFilesystem, f) err := dest.PathFilesystem.MkdirAll(dir, 0o770) if err != nil { diff --git a/pkg/contexts/ocm/compdesc/versions/ocm.software/v3alpha1/jsonscheme/bindata.go b/pkg/contexts/ocm/compdesc/versions/ocm.software/v3alpha1/jsonscheme/bindata.go index 0e1e655f8..37c6f29be 100644 --- a/pkg/contexts/ocm/compdesc/versions/ocm.software/v3alpha1/jsonscheme/bindata.go +++ b/pkg/contexts/ocm/compdesc/versions/ocm.software/v3alpha1/jsonscheme/bindata.go @@ -94,7 +94,7 @@ func ResourcesComponentDescriptorOcmV3SchemaYaml() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "../../../../../../../../resources/component-descriptor-ocm-v3-schema.yaml", size: 10607, mode: os.FileMode(436), modTime: time.Unix(1667477861, 0)} + info := bindataFileInfo{name: "../../../../../../../../resources/component-descriptor-ocm-v3-schema.yaml", size: 10607, mode: os.FileMode(436), modTime: time.Unix(1668066250, 0)} a := &asset{bytes: bytes, info: info} return a, nil } diff --git a/pkg/contexts/ocm/compdesc/versions/v2/jsonscheme/bindata.go b/pkg/contexts/ocm/compdesc/versions/v2/jsonscheme/bindata.go index 4be299477..9925db77d 100644 --- a/pkg/contexts/ocm/compdesc/versions/v2/jsonscheme/bindata.go +++ b/pkg/contexts/ocm/compdesc/versions/v2/jsonscheme/bindata.go @@ -94,7 +94,7 @@ func ResourcesComponentDescriptorV2SchemaYaml() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "../../../../../../../resources/component-descriptor-v2-schema.yaml", size: 10392, mode: os.FileMode(436), modTime: time.Unix(1667477861, 0)} + info := bindataFileInfo{name: "../../../../../../../resources/component-descriptor-v2-schema.yaml", size: 10392, mode: os.FileMode(436), modTime: time.Unix(1668066250, 0)} a := &asset{bytes: bytes, info: info} return a, nil }