From f0343c0faeb8ed7d58e5696a0b55053efeca1f66 Mon Sep 17 00:00:00 2001 From: Attila Tajti Date: Mon, 11 Jan 2016 12:00:37 +0100 Subject: [PATCH] camtool sync: local path support on Windows Change-Id: I2d3e0c0bbd3f3ae50165d366e6a1093fceb36e5c --- cmd/camtool/sync.go | 5 +++-- cmd/camtool/sync_test.go | 17 +++++++++++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/cmd/camtool/sync.go b/cmd/camtool/sync.go index 3be8e9323..5d4a339ec 100644 --- a/cmd/camtool/sync.go +++ b/cmd/camtool/sync.go @@ -22,6 +22,7 @@ import ( "log" "net/http" "os" + "path/filepath" "strconv" "strings" "time" @@ -206,8 +207,8 @@ func (c *syncCmd) storageFromParam(which storageType, val string) (blobserver.St } func looksLikePath(v string) bool { - prefix := func(s string) bool { return strings.HasPrefix(v, s) } - return prefix("./") || prefix("/") || prefix("../") + prefix := func(s string) bool { return strings.HasPrefix(filepath.ToSlash(v), s) } + return prefix("./") || prefix("/") || prefix("../") || filepath.VolumeName(v) != "" } type SyncStats struct { diff --git a/cmd/camtool/sync_test.go b/cmd/camtool/sync_test.go index d8e7148a5..c1df5edca 100644 --- a/cmd/camtool/sync_test.go +++ b/cmd/camtool/sync_test.go @@ -17,14 +17,16 @@ limitations under the License. package main import ( + "runtime" "testing" ) func TestLooksLikePath(t *testing.T) { - tests := []struct { + type pathTest struct { v string want bool - }{ + } + tests := []pathTest{ {"foo.com", false}, {"127.0.0.1:234", false}, {"foo", false}, @@ -33,6 +35,17 @@ func TestLooksLikePath(t *testing.T) { {"./foo", true}, {"../foo", true}, } + if runtime.GOOS == "windows" { + tests = append(tests, + pathTest{`\foo`, true}, + pathTest{`.\foo`, true}, + pathTest{`..\foo`, true}, + pathTest{`C:/dir`, true}, + pathTest{`C:\dir`, true}, + pathTest{`//server/share/dir`, true}, + pathTest{`\\server\share\dir`, true}, + ) + } for _, tt := range tests { got := looksLikePath(tt.v) if got != tt.want {