From 31066a5effd7c8740729996f77e2891bdbb31bc4 Mon Sep 17 00:00:00 2001 From: Mohamed Elbahja Date: Sun, 31 Oct 2021 22:15:43 +0100 Subject: [PATCH 1/4] fix filename and remove updatePath that cause outputing two files. --- download.go | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/download.go b/download.go index ecb5bb8..f0b500e 100644 --- a/download.go +++ b/download.go @@ -42,6 +42,8 @@ type ( path string + unsafeName string + ctx context.Context size, lastSize uint64 @@ -84,6 +86,9 @@ func (d *Download) GetInfoOrDownload() (*Info, error) { return &Info{}, fmt.Errorf("Response status code is not ok: %d", res.StatusCode) } + // Set content disposition non trusted name + d.unsafeName = res.Header.Get("content-disposition") + if dest, err = os.Create(d.Path()); err != nil { return &Info{}, err } @@ -99,8 +104,7 @@ func (d *Download) GetInfoOrDownload() (*Info, error) { l := strings.Split(cr, "/") if len(l) == 2 { if length, err := strconv.ParseUint(l[1], 10, 64); err == nil { - // Update the filename if needed - d.updatePath(getNameFromHeader(res.Header.Get("content-disposition"))) + return &Info{ Size: length, Rangeable: true, @@ -325,25 +329,21 @@ func (d *Download) dl(dest io.WriterAt, errC chan error) { // Return constant path which will not change once the download starts func (d *Download) Path() string { + + // Set the default path if d.path == "" { - // Set the default path + if d.Dest != "" { d.path = d.Dest + } else if d.unsafeName != "" { + d.path = getNameFromHeader(d.unsafeName) } else { d.path = GetFilename(d.URL) } d.path = filepath.Join(d.Dir, d.path) } - return d.path -} -// Update the path onle before the download has started -func (d *Download) updatePath(name string) { - if d.Dest == "" && name != "" { - // Update only if the name is valid and the path - // hasn't been set to dest before, which has higher priority - d.path = filepath.Join(d.Dir, name) - } + return d.path } // DownloadChunk downloads a file chunk. From 4ae4a5fff2a758ce5a8184467305a1980e5c68b3 Mon Sep 17 00:00:00 2001 From: Mohamed Elbahja Date: Sun, 31 Oct 2021 22:16:07 +0100 Subject: [PATCH 2/4] fmt --- cmd/got/variables_unix.go | 1 + cmd/got/variables_windows.go | 1 + 2 files changed, 2 insertions(+) diff --git a/cmd/got/variables_unix.go b/cmd/got/variables_unix.go index 78f2568..f38e317 100644 --- a/cmd/got/variables_unix.go +++ b/cmd/got/variables_unix.go @@ -1,3 +1,4 @@ +//go:build !windows // +build !windows package main diff --git a/cmd/got/variables_windows.go b/cmd/got/variables_windows.go index f6c4d67..e425fc9 100644 --- a/cmd/got/variables_windows.go +++ b/cmd/got/variables_windows.go @@ -1,3 +1,4 @@ +//go:build windows // +build windows package main From a463682c0ec97add4252a44e77e0b2a9009f5e57 Mon Sep 17 00:00:00 2001 From: Mohamed Elbahja Date: Sun, 31 Oct 2021 22:22:10 +0100 Subject: [PATCH 3/4] last try to fix fucking windows --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 7501d73..3e9e15b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -5,7 +5,7 @@ jobs: strategy: matrix: go-version: [1.17.x] - os: [ubuntu-latest, macos-latest, windows-latest] + os: [ubuntu-latest, macos-latest, windows-2016] runs-on: ${{ matrix.os }} steps: - name: Install Go From c8603ffaff6fd56064fd45275ae7fa8500b898ce Mon Sep 17 00:00:00 2001 From: Mohamed Elbahja Date: Sun, 31 Oct 2021 22:24:17 +0100 Subject: [PATCH 4/4] remove fucking windows support --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 3e9e15b..e85119c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -5,7 +5,7 @@ jobs: strategy: matrix: go-version: [1.17.x] - os: [ubuntu-latest, macos-latest, windows-2016] + os: [ubuntu-latest, macos-latest] runs-on: ${{ matrix.os }} steps: - name: Install Go