camtool sync: local path support on Windows

Change-Id: I2d3e0c0bbd3f3ae50165d366e6a1093fceb36e5c
This commit is contained in:
Attila Tajti 2016-01-11 12:00:37 +01:00
parent ea4b5e477a
commit f0343c0fae
2 changed files with 18 additions and 4 deletions

View File

@ -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 {

View File

@ -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 {