Skip to content

Commit

Permalink
Merge pull request #13 from Songmu/fix-dest
Browse files Browse the repository at this point in the history
Make sure to create the destination directory
  • Loading branch information
Songmu committed Apr 3, 2019
2 parents 22dd943 + 64aee5d commit bcb3eec
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
5 changes: 5 additions & 0 deletions cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ func TestCliRun_projDir(t *testing.T) {

cl := &cli{outStream: ioutil.Discard, errStream: ioutil.Discard}
tmpd := setup(t)
// This deletion process is performed to check whether goxz itself creates
// a directory correctly
if err := os.RemoveAll(tmpd); err != nil {
t.Fatal(err)
}
defer os.RemoveAll(tmpd)
args := append([]string{"-d=" + tmpd}, input...)
err := cl.run(args)
Expand Down
18 changes: 14 additions & 4 deletions goxz.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (gx *goxz) run() error {
return err
}

gx.workDir, err = ioutil.TempDir(gx.getDest(), ".goxz-")
gx.workDir, err = ioutil.TempDir(gx.dest, ".goxz-")
if err != nil {
return err
}
Expand Down Expand Up @@ -109,7 +109,10 @@ func (gx *goxz) init() error {
gx.name = filepath.Base(gx.projDir)
}

err := os.MkdirAll(gx.getDest(), 0755)
if err := gx.initDest(); err != nil {
return err
}
err := os.MkdirAll(gx.dest, 0755)
if err != nil {
return err
}
Expand Down Expand Up @@ -168,11 +171,18 @@ func resolvePlatforms(os, arch string) ([]*platform, error) {
return uniqPlatforms, nil
}

func (gx *goxz) getDest() string {
func (gx *goxz) initDest() error {
if gx.dest == "" {
gx.dest = "goxz"
}
return gx.dest
if !filepath.IsAbs(gx.dest) {
var err error
gx.dest, err = filepath.Abs(gx.dest)
if err != nil {
return err
}
}
return nil
}

var resourceReg = regexp.MustCompile(`(?i)^(?:readme|license|credit|install|changelog)`)
Expand Down

0 comments on commit bcb3eec

Please sign in to comment.