[erlang-patches] prim_file:exists/{1,2} a new lightweight file existence check

Blaine Whittle BWhittle@REDACTED
Fri Oct 8 03:57:13 CEST 2010


I haven't tested the function on pipes or block devices.

Although this was written with the assumption of testing for files, the function can be used to check for directories by matching the result against {error, eisdir}.

 
-----Original Message-----
From: dave.peticolas@REDACTED [mailto:dave.peticolas@REDACTED] On Behalf Of Dave Peticolas
Sent: Thursday, October 07, 2010 6:40 PM
To: Blaine Whittle
Cc: erlang-patches@REDACTED
Subject: Re: [erlang-patches] prim_file:exists/{1,2} a new lightweight file existence check

On Thu, Oct 7, 2010 at 4:52 PM, Blaine Whittle <BWhittle@REDACTED> wrote:
> This function is meant to be faster / simpler check for the existence
> of a file or directory.  Most all erlang functions that do this end
> up calling prim_file:read_file_info at some point.   When
> read_file_info is used as a simple existence check, time is wasted
> collecting file stats data only to turn around and throw the data
> away.  If a file exists, read_file_info can take three times longer
> to return than when the file doesn't exist.  Return values are true,
> false, or {error, eisdir}.  The low level implementation of this
> function was already defined via efile_may_openfile, this patch just
> exposes it to prim_file.  filelib:is_dir/1, filelib:is_file/1,
> filelib:is_regular/1 could be changed from calling read_file_info to
> prim_file:exists or better yet to calling to a yet unwritten
> file:exists function.

But efile_may_openfile isn't just testing existence is it? As I read it it
requires the path to be a regular file. What if you want to test for the
existence of a pipe or a block device?


> Patch located at
> git fetch git://github.com/bwhittle/otp.git efile_exists
>
> Note that I mapped the API function to 33 instead of 32.   This is just
> for my own convenience as I use the raw_copy patch which currently
> defines raw_copy at 32.   If the raw_copy patch submission doesn't
> work out, the FILE_EXISTS macro can be easily refactored from 33 to
> 32 by changing efile_drv.c and prim_file.erl.
>
>


More information about the erlang-patches mailing list