Skip to content

Commit 288d63c

Browse files
committed
Use provider.Decompress for provider.Gitlab
1 parent 57517d5 commit 288d63c

File tree

5 files changed

+37
-37
lines changed

5 files changed

+37
-37
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ This project is currently under construction, here is some of the things to come
8686
- **Feb 7, 2021**: Minor: The `BinaryName` variable used in `Updater` have been renamed to `ExecutableName`.
8787
- **Feb 12, 2021**: Minor: The method `Updater.Update()` now returns `(UpdateStatus, error)` instead of just `(error)`.
8888
- **Feb 14, 2021**: Major: The `ExecutableName` variable used in `Updater` is no longer suffixed with `"_" + runtime.GOOS + "_" + runtime.GOARCH`.
89-
- **Feb 21, 2021**: Minor: The `ZipName` variable used in `provider.Github` and `provider.Gitlab` have been renamed to `ArchiveName ` with the arrival of `tar.gz` support.
89+
- **Feb 21, 2021**: Minor: The `ZipName` variable used in `provider.Github` and `provider.Gitlab` have been renamed to `ArchiveName ` with the arrival of `tar.gz` support.
9090

9191

9292
[tu]: https://twitter.com/tenntenn

examples/gitlab-simple/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ func main() {
1414
// Example project here: https://gitlab.com/arnaudalies.py/go-rocket-update-example
1515
u := &updater.Updater{
1616
Provider: &provider.Gitlab{
17-
ProjectID: 24021648,
18-
ZipName: fmt.Sprintf("binaries_%s.zip", runtime.GOOS),
17+
ProjectID: 24021648,
18+
ArchiveName: fmt.Sprintf("binaries_%s.zip", runtime.GOOS),
1919
},
2020
ExecutableName: fmt.Sprintf("go-rocket-update-example_%s_%s", runtime.GOOS, runtime.GOARCH),
2121
Version: "v0.0.0",

pkg/provider/provider_github.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ type Github struct {
1919
ArchiveName string // Archive name (the zip/tar.gz you upload for a release on github), example: binaries.zip
2020

2121
tmpDir string // temporary directory this is used internally
22-
DecompressProvider Provider // provider used to decompress the downloaded archive
22+
decompressProvider Provider // provider used to decompress the downloaded archive
2323
archivePath string // path to the downloaded archive (should be in tmpDir)
2424
}
2525

@@ -130,18 +130,18 @@ func (c *Github) Open() (err error) {
130130
if err != nil {
131131
return
132132
}
133-
c.DecompressProvider, err = Decompress(c.archivePath)
133+
c.decompressProvider, err = Decompress(c.archivePath)
134134
if err != nil {
135135
return nil
136136
}
137-
return c.DecompressProvider.Open()
137+
return c.decompressProvider.Open()
138138
}
139139

140140
// Close closes the provider
141141
func (c *Github) Close() error {
142-
if c.DecompressProvider != nil {
143-
c.DecompressProvider.Close()
144-
c.DecompressProvider = nil
142+
if c.decompressProvider != nil {
143+
c.decompressProvider.Close()
144+
c.decompressProvider = nil
145145
}
146146

147147
if len(c.tmpDir) > 0 {
@@ -166,10 +166,10 @@ func (c *Github) GetLatestVersion() (string, error) {
166166

167167
// Walk walks all the files provided
168168
func (c *Github) Walk(walkFn WalkFunc) error {
169-
return c.DecompressProvider.Walk(walkFn)
169+
return c.decompressProvider.Walk(walkFn)
170170
}
171171

172172
// Retrieve file relative to "provider" to destination
173173
func (c *Github) Retrieve(src string, dest string) error {
174-
return c.DecompressProvider.Retrieve(src, dest)
174+
return c.decompressProvider.Retrieve(src, dest)
175175
}

pkg/provider/provider_gitlab.go

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ import (
1313
"github.com/mouuff/go-rocket-update/internal/fileio"
1414
)
1515

16-
// Gitlab provider finds a zip file in the repository's releases to provide files
16+
// Gitlab provider finds a archive file in the repository's releases to provide files
1717
type Gitlab struct {
18-
ProjectID int
19-
ZipName string // Zip name (the zip you upload for a release on gitlab), example: binaries.zip
18+
ProjectID int
19+
ArchiveName string // ArchiveName (the archive you upload for a release on gitlab), example: binaries.zip
2020

21-
tmpDir string // temporary directory this is used internally
22-
zipProvider *Zip // provider used to unzip the downloaded zip
23-
zipPath string // path to the downloaded zip (should be in tmpDir)
21+
tmpDir string // temporary directory this is used internally
22+
decompressProvider Provider // provider used to decompress the downloaded archive
23+
decompressPath string // path to the downloaded archive (should be in tmpDir)
2424
}
2525

2626
// gitlabRelease struct used to unmarshal response from gitlab
@@ -46,19 +46,19 @@ func (c *Gitlab) getReleasesURL() (string, error) {
4646
), nil
4747
}
4848

49-
// getZipURL get the zip URL for the gitlab repository
49+
// getArchiveURL get the archive URL for the gitlab repository
5050
// the latest version is selected
51-
func (c *Gitlab) getZipURL() (string, error) {
51+
func (c *Gitlab) getArchiveURL() (string, error) {
5252
release, err := c.getLatestRelease()
5353
if err != nil {
5454
return "", err
5555
}
5656
for _, link := range release.Assets.Links {
57-
if strings.HasSuffix(link.Name, c.ZipName) {
57+
if strings.HasSuffix(link.Name, c.ArchiveName) {
5858
return link.DirectURL, nil
5959
}
6060
}
61-
return "", errors.New("Link not found for name: " + c.ZipName)
61+
return "", errors.New("Link not found for name: " + c.ArchiveName)
6262
}
6363

6464
// getReleases gets tags of the repository
@@ -93,11 +93,11 @@ func (c *Gitlab) getLatestRelease() (*gitlabRelease, error) {
9393

9494
// Open opens the provider
9595
func (c *Gitlab) Open() (err error) {
96-
zipURL, err := c.getZipURL() // get zip url for latest version
96+
archiveURL, err := c.getArchiveURL() // get archive url for latest version
9797
if err != nil {
9898
return
9999
}
100-
resp, err := http.Get(zipURL)
100+
resp, err := http.Get(archiveURL)
101101
if err != nil {
102102
return
103103
}
@@ -108,31 +108,31 @@ func (c *Gitlab) Open() (err error) {
108108
return
109109
}
110110

111-
c.zipPath = filepath.Join(c.tmpDir, c.ZipName)
112-
zipFile, err := os.Create(c.zipPath)
111+
c.decompressPath = filepath.Join(c.tmpDir, c.ArchiveName)
112+
archiveFile, err := os.Create(c.decompressPath)
113113
if err != nil {
114114
return
115115
}
116-
_, err = io.Copy(zipFile, resp.Body)
117-
zipFile.Close()
116+
_, err = io.Copy(archiveFile, resp.Body)
117+
archiveFile.Close()
118118
if err != nil {
119119
return
120120
}
121-
c.zipProvider = &Zip{Path: c.zipPath}
122-
return c.zipProvider.Open()
121+
c.decompressProvider, err = Decompress(c.decompressPath)
122+
return c.decompressProvider.Open()
123123
}
124124

125125
// Close closes the provider
126126
func (c *Gitlab) Close() error {
127-
if c.zipProvider != nil {
128-
c.zipProvider.Close()
129-
c.zipProvider = nil
127+
if c.decompressProvider != nil {
128+
c.decompressProvider.Close()
129+
c.decompressProvider = nil
130130
}
131131

132132
if len(c.tmpDir) > 0 {
133133
os.RemoveAll(c.tmpDir)
134134
c.tmpDir = ""
135-
c.zipPath = ""
135+
c.decompressPath = ""
136136
}
137137
return nil
138138
}
@@ -148,10 +148,10 @@ func (c *Gitlab) GetLatestVersion() (string, error) {
148148

149149
// Walk walks all the files provided
150150
func (c *Gitlab) Walk(walkFn WalkFunc) error {
151-
return c.zipProvider.Walk(walkFn)
151+
return c.decompressProvider.Walk(walkFn)
152152
}
153153

154154
// Retrieve file relative to "provider" to destination
155155
func (c *Gitlab) Retrieve(src string, dest string) error {
156-
return c.zipProvider.Retrieve(src, dest)
156+
return c.decompressProvider.Retrieve(src, dest)
157157
}

pkg/provider/provider_gitlab_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import (
1010

1111
func TestProviderGitlab(t *testing.T) {
1212
p := &provider.Gitlab{
13-
ProjectID: 24021648,
14-
ZipName: fmt.Sprintf("binaries_%s.zip", runtime.GOOS),
13+
ProjectID: 24021648,
14+
ArchiveName: fmt.Sprintf("binaries_%s.zip", runtime.GOOS),
1515
}
1616

1717
if err := p.Open(); err != nil {

0 commit comments

Comments
 (0)