Skip to content

Commit

Permalink
Merge pull request #7 from carapace-sh/fix-missing-dir
Browse files Browse the repository at this point in the history
create directory if missing
  • Loading branch information
rsteube authored Nov 21, 2024
2 parents 441b39c + c497c02 commit c9416d1
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion selfupdate.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,20 @@ func (c config) Install(tag, asset string) error {
return err
}

if _, err := os.Stat(binDir); errors.Is(err, os.ErrNotExist) {
c.Printf("creating directory %#v\n", binDir)
if err := os.MkdirAll(binDir, os.ModePerm); err != nil {
return err
}
}

fExecutable, err := os.Create(filepath.Join(binDir, c.binary+".selfupdate"))
if err != nil {
return err
}
defer f.Close()

c.Printf("extracting to %#v\n", fExecutable.Name())
if err := c.extract(tmpArchive.Name(), fExecutable); err != nil {
return err
}
Expand Down Expand Up @@ -196,7 +204,6 @@ func (c config) verify(executable string) error {
}

func (c config) extract(source string, out io.Writer) error {
c.Println("extracting binary")
switch {
case strings.HasSuffix(source, ".tar.gz"):
command := exec.Command("tar", "--to-stdout", "-xzvf", source, c.binary)
Expand Down

0 comments on commit c9416d1

Please sign in to comment.