corrected file URL generation on windows. #205

Merged
merged 1 commit into from Apr 20, 2016
Jump to file or symbol
Failed to load files and symbols.
+14 −34
Split
View
@@ -9,7 +9,6 @@ import (
"fmt"
"os"
"path/filepath"
- "strings"
"syscall"
"unsafe"
@@ -65,33 +64,14 @@ func ReplaceFile(source, destination string) error {
// MakeFileURL returns a proper file URL for the given path/directory
func MakeFileURL(in string) string {
- var volumeName string
- if strings.HasPrefix(in, "file://") {
- volumeName = filepath.VolumeName(strings.TrimPrefix(in, "file://"))
- } else {
- volumeName = filepath.VolumeName(in)
+ in = filepath.ToSlash(in)
+ // for windows at least should be <letter>: to be considered valid
+ // so we cant do anything with less than that.
+ if len(in) < 2 {
+ return in
}
-
- if volumeName != "" {
- // Strip colon
- volumeName = strings.TrimSuffix(volumeName, ":")
-
- // Do not apply function twice
- if strings.HasPrefix(in, "file://\\\\localhost\\") {
- return in
- }
-
- in = filepath.ToSlash(in)
- prefix := "file://\\\\localhost\\" + volumeName + "$"
- if strings.HasPrefix(in, volumeName) {
- return prefix + strings.TrimPrefix(in, volumeName+":")
- }
- if strings.HasPrefix(in, "file://"+volumeName) {
- return prefix + strings.TrimPrefix(in, "file://"+volumeName+":")
- }
- }
-
- return in
+ // since go 1.6 http client will only take this format.
+ return "file://" + in
}
func getUserSID(username string) (string, error) {
View
8 file_windows_test.go 100755 → 100644
@@ -23,16 +23,16 @@ func (s *windowsFileSuite) TestMakeFileURL(c *gc.C) {
expected string
}{{
in: "file://C:\\foo\\baz",
- expected: "file://\\\\localhost\\C$/foo/baz",
+ expected: "file://C:/foo/baz",
}, {
in: "C:\\foo\\baz",
- expected: "file://\\\\localhost\\C$/foo/baz",
+ expected: "file://C:/foo/baz",
}, {
in: "http://foo/baz",
expected: "http://foo/baz",
}, {
- in: "file://\\\\localhost\\C$/foo/baz",
- expected: "file://\\\\localhost\\C$/foo/baz",
+ in: "file://C:/foo/baz",
+ expected: "file://C:/foo/baz",
}}
for i, t := range makeFileURLTests {
@@ -268,7 +268,7 @@ func (s *ManagerSuite) TestSimpleErrorCases(c *gc.C) {
expectedErrMsg = `E: I done failed :(`
)
state := os.ProcessState{}
- cmdError := &exec.ExitError{&state}
+ cmdError := &exec.ExitError{ProcessState: &state}
cmdChan := s.HookCommandOutput(&manager.CommandOutput, []byte(expectedErrMsg), error(cmdError))
@@ -47,7 +47,7 @@ func (s *UtilsSuite) TestRunCommandWithRetryDoesNotCallCombinedOutputTwice(c *gc
const minRetries = 3
var calls int
state := os.ProcessState{}
- cmdError := &exec.ExitError{&state}
+ cmdError := &exec.ExitError{ProcessState: &state}
s.PatchValue(&manager.AttemptStrategy, utils.AttemptStrategy{Min: minRetries})
s.PatchValue(&manager.ProcessStateSys, func(*os.ProcessState) interface{} {
return mockExitStatuser(100) // retry each time.
@@ -85,7 +85,7 @@ func (s *UtilsSuite) TestRunCommandWithRetryStopsWithFatalError(c *gc.C) {
const minRetries = 3
var calls int
state := os.ProcessState{}
- cmdError := &exec.ExitError{&state}
+ cmdError := &exec.ExitError{ProcessState: &state}
s.PatchValue(&manager.AttemptStrategy, utils.AttemptStrategy{Min: minRetries})
s.PatchValue(&manager.ProcessStateSys, func(*os.ProcessState) interface{} {
return mockExitStatuser(100) // retry each time.