Skip to content

Commit c497c02

Browse files
committed
create directory if missing
1 parent 441b39c commit c497c02

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

selfupdate.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,12 +156,20 @@ func (c config) Install(tag, asset string) error {
156156
return err
157157
}
158158

159+
if _, err := os.Stat(binDir); errors.Is(err, os.ErrNotExist) {
160+
c.Printf("creating directory %#v\n", binDir)
161+
if err := os.MkdirAll(binDir, os.ModePerm); err != nil {
162+
return err
163+
}
164+
}
165+
159166
fExecutable, err := os.Create(filepath.Join(binDir, c.binary+".selfupdate"))
160167
if err != nil {
161168
return err
162169
}
163170
defer f.Close()
164171

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

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

0 commit comments

Comments
 (0)