Skip to content

Commit

Permalink
🩹 Use filepath.Base instead of path.Base
Browse files Browse the repository at this point in the history
path.Base only works with '/' while 'filepath.Glob' returns path with '\' on windows
  • Loading branch information
s-weigand committed Nov 7, 2023
1 parent c7539c8 commit 85fc41c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
10 changes: 5 additions & 5 deletions release.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package main
import (
"fmt"
"os"
"path"
"path/filepath"

"code.gitea.io/sdk/gitea"
)
Expand Down Expand Up @@ -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
Expand All @@ -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)
}
Expand All @@ -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)
}

Expand Down
3 changes: 2 additions & 1 deletion utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"hash/crc32"
"io"
"os"
"path/filepath"
"strconv"

"golang.org/x/crypto/blake2b"
Expand Down Expand Up @@ -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))
}
}

Expand Down

0 comments on commit 85fc41c

Please sign in to comment.