Skip to content

Commit

Permalink
fix windows drive volume mounting
Browse files Browse the repository at this point in the history
  • Loading branch information
fenxiong committed Sep 14, 2018
1 parent e8b5229 commit 20c98cc
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
17 changes: 16 additions & 1 deletion agent/api/task/task_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,22 @@ func (task *Task) downcaseAllVolumePaths() {
}

func getCanonicalPath(path string) string {
return filepath.Clean(strings.ToLower(path))
lowercasedPath := strings.ToLower(path)
// if the path is a bare drive like "d:", don't filepath.Clean it because it will add a '.'.
// this is to fix the case where mounting from D:\ to D: is supported by docker but not ecs
if isBareDrive(lowercasedPath) {
return lowercasedPath
}

return filepath.Clean(lowercasedPath)
}

func isBareDrive(path string) bool {
if filepath.VolumeName(path) == path {
return true
}

return false
}

// platformHostConfigOverride provides an entry point to set up default HostConfig options to be
Expand Down
26 changes: 26 additions & 0 deletions agent/api/task/task_windows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,3 +295,29 @@ func TestCPUPercentBasedOnUnboundedEnabled(t *testing.T) {
})
}
}

func TestGetCanonicalPath(t *testing.T) {
testcases := []struct {
name string
path string
expectedResult string
}{
{
name: "folderPath",
path: `C:\myFile`,
expectedResult: `c:\myfile`,
},
{
name: "drivePath",
path: `D:`,
expectedResult: `d:`,
},
}

for _, tc := range testcases {
t.Run(tc.name, func(t *testing.T) {
result := getCanonicalPath(tc.path)
assert.Equal(t, result, tc.expectedResult)
})
}
}

0 comments on commit 20c98cc

Please sign in to comment.