prim_file:exists/{1,2} a new lightweight file existence check

Blaine Whittle BWhittle@REDACTED
Fri Oct 8 01:52:49 CEST 2010


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.

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