diff --git a/cmds/ocm/commands/ocmcmds/componentarchive/create/cmd.go b/cmds/ocm/commands/ocmcmds/componentarchive/create/cmd.go index b10e381bfd..0927dafaef 100644 --- a/cmds/ocm/commands/ocmcmds/componentarchive/create/cmd.go +++ b/cmds/ocm/commands/ocmcmds/componentarchive/create/cmd.go @@ -132,7 +132,6 @@ func (o *Command) Run() error { } obj, err := comparch.Create(o.Context.OCMContext(), accessobj.ACC_CREATE, fp, mode, o.Handler, fs) if err != nil { - fs.RemoveAll(fp) return err } desc := obj.GetDescriptor() diff --git a/pkg/common/accessobj/format-directory.go b/pkg/common/accessobj/format-directory.go index 104a163ff8..07edad78cf 100644 --- a/pkg/common/accessobj/format-directory.go +++ b/pkg/common/accessobj/format-directory.go @@ -62,10 +62,15 @@ func (_ DirectoryHandler) Create(info AccessObjectInfo, path string, opts access } rep, err := projectionfs.New(opts.GetPathFileSystem(), path) if err != nil { + opts.GetPathFileSystem().RemoveAll(path) return nil, errors.Wrapf(err, "unable to create projected filesystem from path %s", path) } opts.SetRepresentation(rep) - return NewAccessObject(info, ACC_CREATE, rep, nil, nil, mode) + obj, err := NewAccessObject(info, ACC_CREATE, rep, nil, nil, mode) + if err != nil { + opts.GetPathFileSystem().RemoveAll(path) + } + return obj, err } // WriteToFilesystem writes the current object to a filesystem.