Skip to content
This repository has been archived by the owner on Dec 17, 2024. It is now read-only.

Commit

Permalink
Merge pull request #69 from vania-pooh/master
Browse files Browse the repository at this point in the history
Lowercasing driver letter for Windows paths (related to #55)
  • Loading branch information
vania-pooh authored Aug 4, 2017
2 parents 9edbd38 + ff4b27d commit 8e3b294
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
10 changes: 9 additions & 1 deletion selenoid/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"strings"
"time"

"regexp"
"runtime"
. "vbom.ml/util/sortorder"
)
Expand Down Expand Up @@ -478,7 +479,14 @@ func (c *DockerConfigurator) getVolumeConfigDir(elem []string) string {

// According to https://stackoverflow.com/questions/34161352/docker-sharing-a-volume-on-windows-with-docker-toolbox
func postProcessPath(path string) string {
return "/" + strings.Replace(strings.Replace(path, string("\\"), "/", -1), ":", "", 1)
if len(path) >= 2 {
replacedSlashes := strings.Replace(path, string("\\"), "/", -1)
re := regexp.MustCompile("([A-Z]):(.+)")
lowerCaseDriveLetter := strings.ToLower(re.ReplaceAllString(replacedSlashes, "$1"))
pathTail := re.ReplaceAllString(replacedSlashes, "$2")
return "/" + lowerCaseDriveLetter + pathTail
}
return path
}

func chooseVolumeConfigDir(defaultConfigDir string, elem []string) string {
Expand Down
6 changes: 4 additions & 2 deletions selenoid/docker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,8 @@ func TestChooseVolumeConfigDir(t *testing.T) {
}

func TestPostProcessPath(t *testing.T) {
AssertThat(t, postProcessPath("c:\\Users\\admin"), EqualTo{"/c/Users/admin"})
AssertThat(t, postProcessPath("c:\\c:\\Users\\admin"), EqualTo{"/c/c:/Users/admin"})
AssertThat(t, postProcessPath("C:\\Users\\admin"), EqualTo{"/c/Users/admin"})
AssertThat(t, postProcessPath("C:\\C:\\Users\\admin"), EqualTo{"/c/C:/Users/admin"})
AssertThat(t, postProcessPath("1"), EqualTo{"1"})
AssertThat(t, postProcessPath(""), EqualTo{""})
}

0 comments on commit 8e3b294

Please sign in to comment.