Skip to content

Commit

Permalink
fix send dir on Windows
Browse files Browse the repository at this point in the history
Closes: #16 [via git-merge-pr]
  • Loading branch information
rixtox authored and psanford committed Jul 12, 2020
1 parent 458e4cf commit 5a9f59f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
7 changes: 5 additions & 2 deletions wormhole/send.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions wormhole/wormhole_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"io"
"io/ioutil"
"net"
"path/filepath"
"strings"
"sync"
"testing"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 5a9f59f

Please sign in to comment.