Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

create directory if missing #7

Merged
merged 1 commit into from
Nov 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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