From c497c02241dbc84e81367d0afa6b9c56e593bf42 Mon Sep 17 00:00:00 2001 From: rsteube Date: Thu, 21 Nov 2024 23:57:14 +0100 Subject: [PATCH] create directory if missing --- selfupdate.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/selfupdate.go b/selfupdate.go index c085339..1460517 100644 --- a/selfupdate.go +++ b/selfupdate.go @@ -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 } @@ -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)