From 5a9f59f3536b9ec739ffbf13b93be555a9807e08 Mon Sep 17 00:00:00 2001 From: RixTox Date: Fri, 10 Jul 2020 21:23:12 -0700 Subject: [PATCH] fix send dir on Windows Closes: #16 [via git-merge-pr] --- wormhole/send.go | 7 +++++-- wormhole/wormhole_test.go | 5 +++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/wormhole/send.go b/wormhole/send.go index 7e1c1736..f2efc963 100644 --- a/wormhole/send.go +++ b/wormhole/send.go @@ -525,12 +525,15 @@ func makeTmpZip(directoryName string, entries []DirectoryEntry) (*zipResult, err var totalBytes int64 for _, entry := range entries { - if !strings.HasPrefix(entry.Path, directoryName+"/") { + entryPath := filepath.ToSlash(entry.Path) + prefixPath := filepath.ToSlash(directoryName) + "/" + + if !strings.HasPrefix(entryPath, prefixPath) { return nil, errors.New("each directory entry must be prefixed with the directoryName") } header := &zip.FileHeader{ - Name: strings.TrimPrefix(entry.Path, directoryName+"/"), + Name: strings.TrimPrefix(entryPath, prefixPath), Method: zip.Deflate, } header.SetMode(entry.Mode) diff --git a/wormhole/wormhole_test.go b/wormhole/wormhole_test.go index f88acfd4..b01250ee 100644 --- a/wormhole/wormhole_test.go +++ b/wormhole/wormhole_test.go @@ -10,6 +10,7 @@ import ( "io" "io/ioutil" "net" + "path/filepath" "strings" "sync" "testing" @@ -322,14 +323,14 @@ func TestWormholeDirectoryTransportSendRecvDirect(t *testing.T) { entries := []DirectoryEntry{ { - Path: "skyjacking/personalize.txt", + Path: filepath.Join("skyjacking", "personalize.txt"), Reader: func() (io.ReadCloser, error) { b := bytes.NewReader(personalizeContent) return ioutil.NopCloser(b), nil }, }, { - Path: "skyjacking/bodice-Maytag.txt", + Path: filepath.Join("skyjacking", "bodice-Maytag.txt"), Reader: func() (io.ReadCloser, error) { b := bytes.NewReader(bodiceContent) return ioutil.NopCloser(b), nil