From 85fc41c229c3714a6a2ee767e5ed8b2b8b6b4048 Mon Sep 17 00:00:00 2001 From: s-weigand Date: Mon, 7 Aug 2023 19:14:16 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=A9=B9=20Use=20filepath.Base=20instead=20?= =?UTF-8?q?of=20path.Base?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit path.Base only works with '/' while 'filepath.Glob' returns path with '\' on windows --- release.go | 10 +++++----- utils.go | 3 ++- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/release.go b/release.go index e80d84b..2171774 100644 --- a/release.go +++ b/release.go @@ -3,7 +3,7 @@ package main import ( "fmt" "os" - "path" + "path/filepath" "code.gitea.io/sdk/gitea" ) @@ -86,12 +86,12 @@ func (rc *releaseClient) uploadFiles(releaseID int64, files []string) error { files: for _, file := range files { for _, attachment := range attachments { - if attachment.Name == path.Base(file) { + if attachment.Name == filepath.Base(file) { switch rc.FileExists { case "overwrite": // do nothing case "fail": - return fmt.Errorf("Asset file %s already exists", path.Base(file)) + return fmt.Errorf("Asset file %s already exists", filepath.Base(file)) case "skip": fmt.Printf("Skipping pre-existing %s artifact\n", attachment.Name) continue files @@ -112,7 +112,7 @@ files: } for _, attachment := range attachments { - if attachment.Name == path.Base(file) { + if attachment.Name == filepath.Base(file) { if _, err := rc.Client.DeleteReleaseAttachment(rc.Owner, rc.Repo, releaseID, attachment.ID); err != nil { return fmt.Errorf("Failed to delete %s artifact: %s", file, err) } @@ -121,7 +121,7 @@ files: } } - if _, _, err = rc.Client.CreateReleaseAttachment(rc.Owner, rc.Repo, releaseID, handle, path.Base(file)); err != nil { + if _, _, err = rc.Client.CreateReleaseAttachment(rc.Owner, rc.Repo, releaseID, handle, filepath.Base(file)); err != nil { return fmt.Errorf("Failed to upload %s artifact: %s", file, err) } diff --git a/utils.go b/utils.go index a406aa3..5f7e161 100644 --- a/utils.go +++ b/utils.go @@ -10,6 +10,7 @@ import ( "hash/crc32" "io" "os" + "path/filepath" "strconv" "golang.org/x/crypto/blake2b" @@ -70,7 +71,7 @@ func writeChecksums(files, methods []string) ([]string, error) { return nil, err } - checksums[method] = append(checksums[method], hash, file) + checksums[method] = append(checksums[method], hash, filepath.Base(file)) } }