From d26b288cde513990f806708edee452a0d046f1ac Mon Sep 17 00:00:00 2001 From: Arsen Musayelyan Date: Sat, 28 Jan 2023 20:53:06 -0800 Subject: [PATCH] Switch to new download system --- build.go | 14 ++++++++------ internal/dl/dl.go | 2 +- internal/dl/file.go | 6 +++--- internal/shutils/nop.go | 4 ++-- 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/build.go b/build.go index 825b6ff..21f9cd4 100644 --- a/build.go +++ b/build.go @@ -22,6 +22,7 @@ import ( "bytes" "context" "encoding/hex" + "fmt" "io" "os" "path/filepath" @@ -40,10 +41,10 @@ import ( "github.com/goreleaser/nfpm/v2/files" "go.arsenm.dev/logger/log" "go.arsenm.dev/lure/distro" - "go.arsenm.dev/lure/download" "go.arsenm.dev/lure/internal/cliutils" "go.arsenm.dev/lure/internal/config" "go.arsenm.dev/lure/internal/cpu" + "go.arsenm.dev/lure/internal/dl" "go.arsenm.dev/lure/internal/repos" "go.arsenm.dev/lure/internal/shutils" "go.arsenm.dev/lure/internal/shutils/decoder" @@ -548,10 +549,11 @@ func getSources(ctx context.Context, srcdir string, bv *BuildVars) error { } for i, src := range bv.Sources { - opts := download.GetOptions{ - SourceURL: src, + opts := dl.Options{ + Name: fmt.Sprintf("%s[%d]", bv.Name, i), + URL: src, Destination: srcdir, - EncloseGit: true, + Progress: os.Stderr, } if !strings.EqualFold(bv.Checksums[i], "SKIP") { @@ -559,10 +561,10 @@ func getSources(ctx context.Context, srcdir string, bv *BuildVars) error { if err != nil { return err } - opts.SHA256Sum = checksum + opts.SHA256 = checksum } - err := download.Get(ctx, opts) + err := dl.Download(ctx, opts) if err != nil { return err } diff --git a/internal/dl/dl.go b/internal/dl/dl.go index 44a7c35..c82f3f4 100644 --- a/internal/dl/dl.go +++ b/internal/dl/dl.go @@ -212,7 +212,7 @@ func linkDir(src, dest string) error { newPath := filepath.Join(dest, rel) if info.IsDir() { - return os.Mkdir(newPath, info.Mode()) + return os.MkdirAll(newPath, info.Mode()) } return os.Link(path, newPath) diff --git a/internal/dl/file.go b/internal/dl/file.go index 02eb99e..958a6f0 100644 --- a/internal/dl/file.go +++ b/internal/dl/file.go @@ -91,7 +91,7 @@ func (FileDownloader) Download(opts Options) (Type, string, error) { } if opts.PostprocDisabled { - return TypeFile, name, nil + return TypeFile, "", nil } _, err = fl.Seek(0, io.SeekStart) @@ -101,7 +101,7 @@ func (FileDownloader) Download(opts Options) (Type, string, error) { format, r, err := archiver.Identify(name, fl) if err == archiver.ErrNoMatch { - return TypeFile, name, nil + return TypeFile, "", nil } else if err != nil { return 0, "", err } @@ -112,7 +112,7 @@ func (FileDownloader) Download(opts Options) (Type, string, error) { } err = os.Remove(path) - return TypeDir, strings.TrimSuffix(name, format.Name()), err + return TypeDir, "", err } func extractFile(r io.Reader, format archiver.Format, name string, opts Options) (err error) { diff --git a/internal/shutils/nop.go b/internal/shutils/nop.go index d4822eb..4c3f542 100644 --- a/internal/shutils/nop.go +++ b/internal/shutils/nop.go @@ -46,8 +46,8 @@ func (NopRWC) Read([]byte) (int, error) { return 0, io.EOF } -func (NopRWC) Write([]byte) (int, error) { - return 0, nil +func (NopRWC) Write(b []byte) (int, error) { + return len(b), nil } func (NopRWC) Close() error {