@@ -65,8 +65,10 @@ impl DockerClient {
65
65
66
66
fn set_workdir ( command : & mut Command ) {
67
67
let path = std:: env:: current_dir ( ) . expect ( "Failed to get current directory" ) ;
68
- let absolute_path = path. canonicalize ( ) . expect ( "Failed to get current directory" ) ;
69
- let current_dir = absolute_path. to_str ( ) . expect ( "Failed to get current directory" ) ;
68
+ let absolute_path = canonicalize_os_path ( & path) . expect ( "Failed to build directory" ) ;
69
+ let current_dir = absolute_path
70
+ . to_str ( )
71
+ . expect ( "Failed to get current directory" ) ;
70
72
71
73
command
72
74
. arg ( "-v" )
@@ -83,6 +85,30 @@ impl DockerClient {
83
85
}
84
86
}
85
87
88
+ fn canonicalize_os_path ( path : & std:: path:: Path ) -> std:: io:: Result < std:: path:: PathBuf > {
89
+ let canonicalized = std:: fs:: canonicalize ( path) ?;
90
+
91
+ if cfg ! ( windows) {
92
+ let path_str = canonicalized. to_str ( ) . unwrap ( ) ;
93
+ // On Windows only, check if the path starts with the UNC prefix
94
+ // example: \\?\C:\path\to\file
95
+ if path_str. starts_with ( r"\\?\" ) {
96
+ // drop UNC prefix
97
+ let path_str = & path_str[ 4 ..] ;
98
+ // grab the drive letter
99
+ let drive_letter = & path_str[ 0 ..1 ] ;
100
+ // swap \ for /
101
+ let rest_of_path = & path_str[ 2 ..] . replace ( r"\" , "/" ) ;
102
+ // rebuild as /C/path/to/file
103
+ return Ok ( std:: path:: PathBuf :: from ( format ! (
104
+ "/{}/{}" ,
105
+ drive_letter, rest_of_path
106
+ ) ) ) ;
107
+ }
108
+ }
109
+ Ok ( canonicalized)
110
+ }
111
+
86
112
#[ cfg( test) ]
87
113
mod tests {
88
114
use super :: * ;
@@ -168,7 +194,7 @@ mod tests {
168
194
assert_eq ! ( command. get_program( ) , "docker" ) ;
169
195
170
196
let binding = current_dir ( ) . unwrap ( ) ;
171
- let absolute_path = binding . canonicalize ( ) . unwrap ( ) ;
197
+ let absolute_path = canonicalize_os_path ( & binding ) . unwrap ( ) ;
172
198
let current_dir = absolute_path. to_str ( ) . unwrap ( ) ;
173
199
174
200
let args: Vec < & OsStr > = command. get_args ( ) . collect ( ) ;
0 commit comments