Skip to content
This repository has been archived by the owner on May 3, 2022. It is now read-only.

Commit

Permalink
Install directly from thick bundle .tgz file
Browse files Browse the repository at this point in the history
Fixes #784
  • Loading branch information
benpatt committed Jul 24, 2019
1 parent 2120871 commit a345cb8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 15 deletions.
6 changes: 5 additions & 1 deletion cmd/duffle/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"
"strings"

Expand Down Expand Up @@ -109,10 +110,13 @@ func (i *installCmd) run() error {
return fmt.Errorf("a claim with the name %v already exists", i.name)
}

bun, err := loadBundle(bundleFile)
bun, tempDir, err := inferAndLoadBundle(bundleFile)
if err != nil {
return err
}
if tempDir != "" {
defer os.RemoveAll(tempDir)
}

if err = bun.Validate(); err != nil {
return err
Expand Down
32 changes: 18 additions & 14 deletions cmd/duffle/relocate.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,28 +121,32 @@ func (r *relocateCmd) run() error {
return r.writeRelocationMapping(relMap)
}

func inferAndLoadBundle(bundleFile string) (*bundle.Bundle, string, error) {
if strings.HasSuffix(bundleFile, ".tgz") {
bun, dest, err := unzipBundle(bundleFile)
if err != nil {
return nil, "", err
}
return bun, dest, nil
}
bun, err := loadBundle(bundleFile)
if err != nil {
return nil, "", err
}
return bun, "", nil
}

// The caller is responsible for running the returned cleanup function, which may delete the returned bundle.
func (r *relocateCmd) setup() (*relocator.Relocator, func(), error) {
nop := func() {}
dest := ""
bundleFile, err := resolveBundleFilePath(r.inputBundle, r.home.String(), r.bundleIsFile)
if err != nil {
return nil, nop, err
}

var bun *bundle.Bundle

if strings.HasSuffix(bundleFile, ".tgz") {
var err error
bun, dest, err = unzipBundle(bundleFile)
if err != nil {
return nil, nop, err
}
} else {
bun, err = loadBundle(bundleFile)
if err != nil {
return nil, nop, err
}
bun, dest, err := inferAndLoadBundle(bundleFile)
if err != nil {
return nil, nop, err
}

if err = bun.Validate(); err != nil {
Expand Down

0 comments on commit a345cb8

Please sign in to comment.