Skip to content

Commit 4891cbf

Browse files
committed
allow more abs paths on windows, transform unix
1 parent b1f10a7 commit 4891cbf

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

cli/open.go

+8-7
Original file line numberDiff line numberDiff line change
@@ -243,14 +243,15 @@ func isWindowsAbsPath(p string) bool {
243243
return filepath.IsAbs(p)
244244
}
245245

246+
// Remove the drive letter, if present.
247+
if len(p) >= 2 && p[1] == ':' {
248+
p = p[2:]
249+
}
250+
246251
switch {
247-
case len(p) < 2:
252+
case len(p) == 0:
248253
return false
249-
case p[1] == ':':
250-
// Path starts with a drive letter.
251-
return len(p) == 2 || (len(p) >= 3 && p[2] == '\\')
252-
case p[0] == '\\' && p[1] == '\\':
253-
// Path starts with \\.
254+
case p[0] == '/' || p[0] == '\\':
254255
return true
255256
default:
256257
return false
@@ -309,7 +310,7 @@ func resolveAgentAbsPath(workingDirectory, relOrAbsPath, agentOS string, local b
309310
case workingDirectory != "" && !isWindowsAbsPath(relOrAbsPath):
310311
return windowsJoinPath(workingDirectory, relOrAbsPath), nil
311312
case isWindowsAbsPath(relOrAbsPath):
312-
return relOrAbsPath, nil
313+
return windowsJoinPath(relOrAbsPath), nil
313314
default:
314315
return "", xerrors.Errorf("path %q not supported, use an absolute path instead", relOrAbsPath)
315316
}

cli/open_internal_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ func Test_resolveAgentAbsPath(t *testing.T) {
3333
{"ok with working directory and rel path on windows", args{workingDirectory: "C:\\some\\path", relOrAbsPath: "other\\path", agentOS: "windows"}, "C:\\some\\path\\other\\path", false},
3434
{"ok with working directory and abs path on windows", args{workingDirectory: "C:\\some\\path", relOrAbsPath: "C:\\other\\path", agentOS: "windows"}, "C:\\other\\path", false},
3535
{"ok with no working directory and abs path on windows", args{relOrAbsPath: "C:\\other\\path", agentOS: "windows"}, "C:\\other\\path", false},
36+
{"ok abs unix path on windows", args{workingDirectory: "C:\\some\\path", relOrAbsPath: "/other/path", agentOS: "windows"}, "\\other\\path", false},
37+
{"ok rel unix path on windows", args{workingDirectory: "C:\\some\\path", relOrAbsPath: "other/path", agentOS: "windows"}, "C:\\some\\path\\other\\path", false},
3638

3739
{"fail with no working directory and rel path on windows", args{relOrAbsPath: "other\\path", agentOS: "windows"}, "", true},
3840
}

0 commit comments

Comments
 (0)