diff --git a/cmd/get.go b/cmd/get.go index c613f4c..018826e 100644 --- a/cmd/get.go +++ b/cmd/get.go @@ -2,11 +2,6 @@ package cmd import ( "fmt" - "github.com/khorevaa/logos" - server "github.com/v8platform/oneget/http-server" - "github.com/v8platform/oneget/unpacker" - "go.uber.org/multierr" - "io/ioutil" "os" "path" "path/filepath" @@ -14,6 +9,11 @@ import ( "strings" "time" + "github.com/khorevaa/logos" + server "github.com/v8platform/oneget/http-server" + "github.com/v8platform/oneget/unpacker" + "go.uber.org/multierr" + "github.com/urfave/cli/v2" dloader "github.com/v8platform/oneget/downloader" ) @@ -291,7 +291,7 @@ func (c *getCmd) extractFiles(files []string) error { } func renameFiles(dir string) error { - files, err := ioutil.ReadDir(dir) + files, err := os.ReadDir(dir) if err != nil { log.Errorf("Error find files in dir <%s> to rename: %s", dir, err.Error()) return err diff --git a/downloader/filter_test.go b/downloader/filter_test.go index 21e30f4..7be30f5 100644 --- a/downloader/filter_test.go +++ b/downloader/filter_test.go @@ -10,16 +10,6 @@ import ( func TestMatchFilter_Match(t *testing.T) { - type args struct { - filters string - project string - } - - type want struct { - source string - want bool - } - tests := []struct { filters string project string @@ -263,8 +253,6 @@ func TestLatestVersionFilter_Filter(t *testing.T) { } func Test_compareVersion(t *testing.T) { - type args struct { - } tests := []struct { v1 string v2 string diff --git a/downloader/html.go b/downloader/html.go index aa7fdec..502b66a 100644 --- a/downloader/html.go +++ b/downloader/html.go @@ -2,10 +2,11 @@ package downloader import ( "fmt" - "github.com/PuerkitoBio/goquery" "io" "strings" "time" + + "github.com/PuerkitoBio/goquery" ) type HtmlParser struct { @@ -52,13 +53,8 @@ func (p *HtmlParser) ParseTotalReleases(body io.Reader) (rows []ProjectInfo, err doc.Find(p.ReleaseTableSelector).Each(func(i int, html *goquery.Selection) { tableHtml = html - return }) - if tableHtml == nil { - return - } - return parseReleasesTable(tableHtml), nil } @@ -74,7 +70,6 @@ func (p *HtmlParser) ParseProjectReleases(body io.Reader) (rows []*ProjectVersio doc.Find(p.ProjectTableSelector).Each(func(i int, html *goquery.Selection) { tableHtml = html - return }) if tableHtml == nil { @@ -165,7 +160,7 @@ func parseReleasesTable(s *goquery.Selection) (rows []ProjectInfo) { info.Name = strings.TrimSpace(releaseRow.Find(".nameColumn").Text()) info.Url, _ = releaseRow.Find(".nameColumn a").Attr("href") - info.ID = strings.TrimLeft(info.Url, "/project/") + info.ID = strings.TrimSuffix(info.Url, "/project/") releaseRow.Find("td").Each(func(i int, rowHtml *goquery.Selection) { diff --git a/downloader/oneDownloader.go b/downloader/oneDownloader.go index 1a7f23e..a521687 100644 --- a/downloader/oneDownloader.go +++ b/downloader/oneDownloader.go @@ -2,15 +2,15 @@ package downloader import ( "fmt" - "go.uber.org/multierr" "io" - "net/http" "net/http/cookiejar" "net/url" "os" "path/filepath" "strings" "sync" + + "go.uber.org/multierr" ) type GetConfig struct { @@ -34,8 +34,7 @@ type OnegetDownloader struct { client *Client - urlCh chan *FileToDownload - wg *sync.WaitGroup + wg *sync.WaitGroup parser *HtmlParser } @@ -223,13 +222,6 @@ func filterProjectVersionInfo(list []*ProjectVersionInfo, filter VersionFilter) } -func (dr *OnegetDownloader) getClient() *http.Client { - return &http.Client{ - Jar: dr.cookie, - Transport: nil, - } -} - func (dr *OnegetDownloader) addFileToChannel(href string, config GetConfig, downloadCh chan *FileToDownload) (err error) { downloadHref := []string{releasesURL + href} @@ -368,13 +360,6 @@ func SaveToFile(reader io.ReadCloser, fileName string) error { return nil } -func (dr *OnegetDownloader) handleError(err error) { - if err == nil { - return - } - log.Error(err.Error()) -} - func (dr *OnegetDownloader) getDownloadFileLinks(href string, _ GetConfig) ([]string, error) { client := dr.client diff --git a/unpacker/unpacker_test.go b/unpacker/unpacker_test.go index bf5e460..7319174 100644 --- a/unpacker/unpacker_test.go +++ b/unpacker/unpacker_test.go @@ -2,12 +2,12 @@ package unpacker import ( "fmt" - "github.com/stretchr/testify/assert" - "io/ioutil" "os" "path/filepath" "regexp" "testing" + + "github.com/stretchr/testify/assert" ) func TestUnpackTarGz(t *testing.T) { @@ -16,7 +16,7 @@ func TestUnpackTarGz(t *testing.T) { defer os.RemoveAll(tempDir) path := filepath.Join("fixtures", "linux", "client") - files, err := ioutil.ReadDir(path) + files, err := os.ReadDir(path) if err != nil { log.Error(err.Error()) } @@ -28,7 +28,7 @@ func TestUnpackTarGz(t *testing.T) { fileGZ := fileName[:len(fileName)-len(filepath.Ext(fileName))] dirName := fileGZ[:len(fileGZ)-len(filepath.Ext(fileGZ))] - files, err := ioutil.ReadDir(filepath.Join(tempDir, dirName)) + files, err := os.ReadDir(filepath.Join(tempDir, dirName)) if err != nil { log.Error(err.Error()) } @@ -100,7 +100,7 @@ func getExpectedName() map[string]string { } func getTempDir() (string, error) { - dir, err := ioutil.TempDir("", "oneget") + dir, err := os.MkdirTemp("", "oneget") if err != nil { log.Error(err.Error()) }