File tree Expand file tree Collapse file tree 2 files changed +22
-4
lines changed Expand file tree Collapse file tree 2 files changed +22
-4
lines changed Original file line number Diff line number Diff line change @@ -996,18 +996,27 @@ defmodule File do
996
996
@ spec cwd ( ) :: { :ok , binary } | { :error , posix }
997
997
def cwd ( ) do
998
998
case F . get_cwd do
999
- { :ok , base } -> { :ok , IO . chardata_to_string ( base ) }
999
+ { :ok , base } -> { :ok , IO . chardata_to_string ( fix_drive_letter ( base ) ) }
1000
1000
{ :error , _ } = error -> error
1001
1001
end
1002
1002
end
1003
1003
1004
+ defp fix_drive_letter ( [ l , ?: , ?/ | rest ] = original ) when l in ?A .. ?Z do
1005
+ case :os . type ( ) do
1006
+ { :win32 , _ } -> [ l + ?a - ?A , ?: , ?/ | rest ]
1007
+ _ -> original
1008
+ end
1009
+ end
1010
+
1011
+ defp fix_drive_letter ( original ) , do: original
1012
+
1004
1013
@ doc """
1005
1014
The same as `cwd/0`, but raises an exception if it fails.
1006
1015
"""
1007
1016
@ spec cwd! ( ) :: binary | no_return
1008
1017
def cwd! ( ) do
1009
- case F . get_cwd do
1010
- { :ok , cwd } -> IO . chardata_to_string ( cwd )
1018
+ case cwd ( ) do
1019
+ { :ok , cwd } -> cwd
1011
1020
{ :error , reason } ->
1012
1021
raise File.Error , reason: reason , action: "get current working directory"
1013
1022
end
Original file line number Diff line number Diff line change @@ -94,11 +94,20 @@ defmodule System do
94
94
"""
95
95
def cwd do
96
96
case :file . get_cwd do
97
- { :ok , base } -> IO . chardata_to_string ( base )
97
+ { :ok , base } -> IO . chardata_to_string ( fix_drive_letter ( base ) )
98
98
_ -> nil
99
99
end
100
100
end
101
101
102
+ defp fix_drive_letter ( [ l , ?: , ?/ | rest ] = original ) when l in ?A .. ?Z do
103
+ case :os . type ( ) do
104
+ { :win32 , _ } -> [ l + ?a - ?A , ?: , ?/ | rest ]
105
+ _ -> original
106
+ end
107
+ end
108
+
109
+ defp fix_drive_letter ( original ) , do: original
110
+
102
111
@ doc """
103
112
Current working directory, exception on error.
104
113
You can’t perform that action at this time.
0 commit comments