Skip to content

Commit 658124e

Browse files
committed
fix: broken paths on Windows
1 parent 78f264e commit 658124e

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed

internal/app/enaptercli/execute.go

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@ import (
55
"bytes"
66
"fmt"
77
"io"
8+
"io/fs"
89
"os"
9-
"path/filepath"
10-
"strings"
1110

1211
"github.com/urfave/cli/v2"
1312
)
@@ -32,34 +31,32 @@ func NewApp() *cli.App {
3231
}
3332

3433
func zipDir(path string) ([]byte, error) {
34+
fsys := os.DirFS(path)
35+
3536
buf := &bytes.Buffer{}
3637
zw := zip.NewWriter(buf)
3738

38-
path = filepath.Clean(path)
39-
err := filepath.WalkDir(path, func(filePath string, entry os.DirEntry, err error) error {
39+
err := fs.WalkDir(fsys, ".", func(path string, entry fs.DirEntry, err error) error {
4040
if err != nil {
4141
return err
4242
}
4343
if entry.IsDir() {
4444
return nil
4545
}
4646

47-
relPath := strings.TrimPrefix(filePath, path)
48-
relPath = strings.TrimPrefix(relPath, "/")
49-
zipFile, err := zw.Create(relPath)
47+
f, err := fsys.Open(path)
5048
if err != nil {
51-
return err
49+
return fmt.Errorf("open: %w", err)
5250
}
51+
defer f.Close()
5352

54-
fsFile, err := os.Open(filePath)
53+
zf, err := zw.Create(path)
5554
if err != nil {
56-
return err
55+
return fmt.Errorf("create: %w", err)
5756
}
58-
defer fsFile.Close()
5957

60-
_, err = io.Copy(zipFile, fsFile)
61-
if err != nil {
62-
return err
58+
if _, err = io.Copy(zf, f); err != nil {
59+
return fmt.Errorf("copy: %w", err)
6360
}
6461
return nil
6562
})

0 commit comments

Comments
 (0)