Skip to content

Commit

Permalink
fix: Fix path on Windows platform
Browse files Browse the repository at this point in the history
  • Loading branch information
tianfeng92 committed Aug 5, 2023
1 parent dfbce5d commit 158a9a0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
4 changes: 2 additions & 2 deletions internal/archive/zip/zip.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ func (w *Writer) Add(src, dst string) (count int, length int, err error) {
}

for _, f := range files {
base := filepath.Base(src)
base := path.Base(src)
rebase := path.Join(dst, base)
fpath := filepath.Join(src, f.Name())
fpath := path.Join(src, f.Name())
fileCount, pathLength, err := w.Add(fpath, rebase)
if err != nil {
return 0, 0, err
Expand Down
10 changes: 8 additions & 2 deletions internal/saucecloud/zip/archive.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package zip
import (
"fmt"
"os"
"path"
"path/filepath"
"sort"
"strings"
Expand Down Expand Up @@ -71,6 +72,11 @@ func ArchiveFiles(targetFileName string, targetDir string, sourceDir string, fil
if err != nil {
return "", err
}
// The file names added should not contain any backslashes according to the specification outlined in
// https://pkware.cachefly.net/webdocs/casestudies/APPNOTE.TXT.
// It's essential to adhere to this specification to ensure compatibility and
// proper functioning of the files across different systems and platforms.
rel = strings.ReplaceAll(rel, string(os.PathSeparator), "/")
fileCount, length, err := z.Add(f, rel)
if err != nil {
return "", err
Expand Down Expand Up @@ -140,7 +146,7 @@ func ArchiveNodeModules(targetDir string, sourceDir string, matcher sauceignore.
}
log.Info().Msgf("Found a total of %d related npm dependencies", len(reqs))
for _, v := range reqs {
files = append(files, filepath.Join(sourceDir, "node_modules", v))
files = append(files, path.Join(sourceDir, "node_modules", v))
}
}

Expand All @@ -150,7 +156,7 @@ func ArchiveNodeModules(targetDir string, sourceDir string, matcher sauceignore.
log.Warn().Msg("Adding the entire node_modules folder to the payload. " +
"This behavior is deprecated, not recommended and will be removed in the future. " +
"Please address your dependency needs via https://docs.saucelabs.com/dev/cli/saucectl/usage/use-cases/#set-npm-packages-in-configyml")
files = append(files, filepath.Join(sourceDir, "node_modules"))
files = append(files, path.Join(sourceDir, "node_modules"))
}

return ArchiveFiles("node_modules", targetDir, sourceDir, files, matcher)
Expand Down

0 comments on commit 158a9a0

Please sign in to comment.