Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/elixir/lib/path.ex
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ defmodule Path do
def relative_to_cwd(path, opts \\ []) when is_list(opts) do
case :file.get_cwd() do
{:ok, base} -> relative_to(path, IO.chardata_to_string(base), opts)
_ -> path
_ -> IO.chardata_to_string(path)
end
end

Expand Down
24 changes: 24 additions & 0 deletions lib/elixir/test/elixir/path_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -430,3 +430,27 @@ defmodule PathTest do
defp strip_drive_letter_if_windows(path), do: path
end
end

defmodule Path.SyncTest do
use ExUnit.Case, async: false

@tag :tmp_dir
@tag :unix
test "relative_to_cwd/2 returns a binary even when cwd cannot be retrieved", config do
{:ok, original} = :file.get_cwd()
tmp = Path.join(config.tmp_dir, "deleted")
File.mkdir_p!(tmp)

try do
File.cd!(tmp)
File.rm_rf!(tmp)
assert {:error, _} = :file.get_cwd()

assert Path.relative_to_cwd("foo/bar") == "foo/bar"
assert Path.relative_to_cwd(~c"foo/bar") == "foo/bar"
assert Path.relative_to_cwd(["foo", ?/, "bar"]) == "foo/bar"
after
:file.set_cwd(original)
end
end
end
Loading