Skip to content

Commit 2eff359

Browse files
author
José Valim
committed
Lowercase drive letters from cwd, closes #2747
1 parent b578f45 commit 2eff359

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

lib/elixir/lib/file.ex

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -996,18 +996,27 @@ defmodule File do
996996
@spec cwd() :: {:ok, binary} | {:error, posix}
997997
def cwd() do
998998
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))}
10001000
{:error, _} = error -> error
10011001
end
10021002
end
10031003

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+
10041013
@doc """
10051014
The same as `cwd/0`, but raises an exception if it fails.
10061015
"""
10071016
@spec cwd!() :: binary | no_return
10081017
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
10111020
{:error, reason} ->
10121021
raise File.Error, reason: reason, action: "get current working directory"
10131022
end

lib/elixir/lib/system.ex

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,20 @@ defmodule System do
9494
"""
9595
def cwd do
9696
case :file.get_cwd do
97-
{:ok, base} -> IO.chardata_to_string(base)
97+
{:ok, base} -> IO.chardata_to_string(fix_drive_letter(base))
9898
_ -> nil
9999
end
100100
end
101101

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+
102111
@doc """
103112
Current working directory, exception on error.
104113

0 commit comments

Comments
 (0)