Proposal: File.lstat and File.lstat! or File.stat(path,:read_link)

66 views
Skip to first unread message

Booker Bense

unread,
Oct 10, 2014, 12:31:59 AM10/10/14
to elixir-l...@googlegroups.com
Currently when there is a symlink pointing to a non-existant file, 

File.stat!(symlink) 

fails. I think this is the "right" think as it is the same result that you would get from the unix stat call or erlang's :read_file_info.
However, there is no Elixir interface to lstat or erlang :read_link_info. 

Adding File.lstat  and File.lstat! seem like the most obvious options, but you could also add an option to File.stat 
similar to the :time option ( i.e. :read_link that switches it to use :read_link_info ) 

I'm willing to write either; adding the :read_link option seems more "elixir" to me, but I don't have a strong opinions about which is "right".

- Booker C. Bense 

José Valim

unread,
Oct 10, 2014, 2:50:03 AM10/10/14
to elixir-l...@googlegroups.com
Great suggestion. Let's go with lstat and lstat!.



José Valim
Skype: jv.ptec
Founder and Lead Developer

--
You received this message because you are subscribed to the Google Groups "elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-co...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Booker Bense

unread,
Oct 10, 2014, 1:24:04 PM10/10/14
to elixir-l...@googlegroups.com, jose....@plataformatec.com.br
Okay, I have a related question. I had a go at implementing the :read_link option last night and 
this code failed. 
if( Keyword.has_key?(opts,:read_link), 
      do: read_info = F.read_link_info , 
      else: read_info = F.read_file_info
case read_info.((IO.chardata_to_string(path), opts) do

but this code worked. 

if( Keyword.has_key?(opts,:read_link), 
      do: read_info = F.read_link_info(IO.chardata_to_string(path), opts) , 
      else: read_info = F.read_file_info(IO.chardata_to_string(path), opts) )
case read_info do

The error message was 

==> elixir (compile)
** (UndefinedFunctionError) undefined function: :file.read_file_info/0

My best guess is that something different is required when matching a direct erlang functions to a variable, since the . convention
doesn't seem to work in this case. What's the right way to call an erlang function to matched to a variable? 

thanks, 

- Booker C. Bense 

Paulo Almeida

unread,
Oct 10, 2014, 1:35:50 PM10/10/14
to elixir-l...@googlegroups.com, jose....@plataformatec.com.br
In the VM a function is identified by both name and arity.

You need to use the & operator to specify you want to capture the function, not call it.

Use read_info = &F.read_link_info/1

Paulo Almeida

unread,
Oct 10, 2014, 1:37:28 PM10/10/14
to elixir-l...@googlegroups.com, jose....@plataformatec.com.br
Noticed the arity is actually 2, so that would be &F.read_file_info/2

Booker Bense

unread,
Oct 10, 2014, 2:19:22 PM10/10/14
to elixir-l...@googlegroups.com, jose....@plataformatec.com.br
Doh!, obvious now that you point it out. I've gotten to used to simply assigning anonymous functions to variables. 

thanks, 

- Booker C. Bense 
Reply all
Reply to author
Forward
0 new messages