Skip to content

Commit b6618c2

Browse files
committed
Download in tmp
1 parent 508d8ae commit b6618c2

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

core/github.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ type Github struct {
3535
const (
3636
defaultVersion = "v0.7.2"
3737
defaultURLPath = "https://github.com/aktau/github-release/releases/download/%s/%s"
38-
defaultFilePath = "github-release"
38+
defaultFilePath = "tmp/github-release"
3939
defaultFileName = "linux-amd64-github-release.tar.bz2"
4040
defaultPackageExtract = "tar -xvjf -"
4141
)
@@ -153,7 +153,7 @@ func (g *Github) download() (err error) {
153153
return fmt.Errorf("Unable to download '%s'. bad status: %s", finalURL, resp.Status)
154154
}
155155

156-
if err = g.UntarFile(g.file, resp.Body); err != nil {
156+
if err = g.UntarFile("tmp", filepath.Base(g.file), resp.Body); err != nil {
157157
return fmt.Errorf("Unable to uncompress tar ball. %s", err)
158158
}
159159

@@ -176,7 +176,7 @@ func (g *Github) download() (err error) {
176176
}
177177

178178
// UntarFile the wanted file
179-
func (g *Github) UntarFile(file string, r io.Reader) error {
179+
func (g *Github) UntarFile(dest, file string, r io.Reader) error {
180180

181181
gzr := bzip2.NewReader(r)
182182

@@ -209,7 +209,13 @@ func (g *Github) UntarFile(file string, r io.Reader) error {
209209

210210
// if it's a file create it
211211
case tar.TypeReg:
212-
f, err := os.OpenFile(file, os.O_CREATE|os.O_RDWR, os.FileMode(header.Mode))
212+
if _, err := os.Stat(dest); err != nil {
213+
if err := os.MkdirAll(dest, 0755); err != nil {
214+
return err
215+
}
216+
}
217+
218+
f, err := os.OpenFile(path.Join(dest, file), os.O_CREATE|os.O_RDWR, os.FileMode(header.Mode))
213219
if err != nil {
214220
return err
215221
}

core/release.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,11 @@ func (r *Release) CheckVersion(version string) (_ int, _ error) {
4444

4545
r.file = fmt.Sprintf(r.fileType, version)
4646

47-
// status 3: File existence
4847
if fi, err := os.Stat(r.file); err != nil {
49-
return 3, fmt.Errorf("Issue accessing %s. %s", r.file, err)
48+
// No release found. The inexistence of a release file is not an error. No return
49+
return 0, fmt.Errorf("No release file found. %s", err)
5050
} else if !fi.Mode().IsRegular() {
51+
// status 3: File existence
5152
return 3, fmt.Errorf("%s is not a regular file. %s", r.file, err)
5253
}
5354

0 commit comments

Comments
 (0)