Skip to content

Commit

Permalink
Fix pid2name return result
Browse files Browse the repository at this point in the history
  • Loading branch information
wkirschbaum committed Mar 31, 2024
1 parent 9c2dc03 commit e1d3854
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions lib/sftpd_file_handler.ex
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,30 @@ defmodule Exsftpd.SftpFileHandler do
result
end

defp get_file_info(io_device) do
defp pid2name(io_device) when is_pid(io_device) do
# This function has code ported from the deprecated Erlang function :file.pid2name.

ref = Process.monitor(io_device)

send(io_device, {:file_request, self(), ref, :pid2name})

receive do
{:file_reply, ref, result} ->
{:file_reply, ref, reply} ->
Process.demonitor(ref, [:flush])
{io_device, result}
reply

{"DOWN", _ref, _, _, _} ->
{io_device}
{:error, :terminated}
after
500 ->
{io_device}
{:error, :timeout}
end
end

defp get_file_info(io_device) do
case pid2name(io_device) do
{:ok, filename} -> {io_device, filename}
_ -> {io_device}
end
end

Expand Down

0 comments on commit e1d3854

Please sign in to comment.