mirror of https://github.com/perkeep/perkeep.git
camtool sync: local path support on Windows
Change-Id: I2d3e0c0bbd3f3ae50165d366e6a1093fceb36e5c
This commit is contained in:
parent
ea4b5e477a
commit
f0343c0fae
|
@ -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 {
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue