Skip to content
This repository has been archived by the owner on Jun 13, 2021. It is now read-only.

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
  • Loading branch information
ndeloof committed Nov 30, 2019
1 parent c8e7433 commit 6d54f0c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
14 changes: 9 additions & 5 deletions internal/commands/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,19 @@ func runPush(dockerCli command.Cli, name string) error {
return err
}

cnabRef := reference.TagNameOnly(ref)

// Push the bundle
dg, err := pushBundle(dockerCli, bndl, cnabRef)
dg, err := pushBundle(dockerCli, bndl, ref)
if err != nil {
return errors.Wrapf(err, "could not push %q", cnabRef)
return errors.Wrapf(err, "could not push %q", ref)
}

// we can't just re-use bndl var here, as fixup did rewrite the bundle
bndl, err = resolveReferenceAndBundle(bundleStore, ref)
if err != nil {
return err
}
bndl.RepoDigest = dg
_, err = bundleStore.Store(bndl, cnabRef)
_, err = bundleStore.Store(bndl, ref)
return err
}

Expand Down
20 changes: 10 additions & 10 deletions internal/relocated/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func BundleFromFile(filename string) (*Bundle, error) {
digestFileName := filepath.Join(filepath.Dir(filename), DigestFilename)
dg, err := repoDigest(digestFileName)
if err != nil {
return nil, errors.Wrapf(err, "failed to read relocation map")
return nil, errors.Wrapf(err, "failed to read digest file")
}

return &Bundle{
Expand All @@ -72,14 +72,18 @@ func (b *Bundle) writeRelocationMap(dest string, mode os.FileMode) error {
// writeRepoDigest store the repo digest to a file as plain text.
func (b *Bundle) writeRepoDigest(dest string, mode os.FileMode) error {
if b.RepoDigest == "" {
if _, err := os.Stat(dest); os.IsNotExist(err) {
return nil
}
return os.Remove(dest)
return cleanRepoDigest(dest)
}
return ioutil.WriteFile(dest, []byte(b.RepoDigest), mode)
}

func cleanRepoDigest(dest string) error {
if _, err := os.Stat(dest); os.IsNotExist(err) {
return nil
}
return os.Remove(dest)
}

// Store a bundle with the relocation map as json files.
func (b *Bundle) Store(dir string) error {
// store bundle.json
Expand Down Expand Up @@ -153,9 +157,5 @@ func repoDigest(digestFileName string) (digest.Digest, error) {
if err != nil {
return "", err
}
dg, err := digest.Parse(string(bytes))
if err != nil {
return "", err
}
return dg, nil
return digest.Parse(string(bytes))
}

0 comments on commit 6d54f0c

Please sign in to comment.