Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

corrected file URL generation on windows. #205

Merged
merged 1 commit into from Apr 20, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
34 changes: 7 additions & 27 deletions file_windows.go
Expand Up @@ -9,7 +9,6 @@ import (
"fmt"
"os"
"path/filepath"
"strings"
"syscall"
"unsafe"

Expand Down Expand Up @@ -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) {
Expand Down
8 changes: 4 additions & 4 deletions file_windows_test.go 100755 → 100644
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion packaging/manager/manager_test.go
Expand Up @@ -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))

Expand Down
4 changes: 2 additions & 2 deletions packaging/manager/utils_test.go
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down