[RFC PATCH] Ignore {error,eexist} in filelib:ensure_dir/1

Tuncer Ayaz <>
Fri Jan 15 17:59:27 CET 2010

Ignore {error,eexist} in filelib:ensure_dir/1

This is about the non-atomicity of filelib:ensure_dir/1.

When using filelib:ensure_dir/1 from multiple processes to create
the same path or parts of the same directory structure (which happens
with rebar's worker processes) it happens quite a lot that between
a file:read_file_info/1 and file:make_dir/1 one of the other procs
has already created the directory we want to create.

mkdir(1) says one of the following depending on which Unix like
system you're on:
"no error if existing"
"no error will be reported if a directory given as an operand already

I've seen more than one Erlang project where the return value of
ensure_dir/1 is ignored completely.

I think {error,eexist} is safe to ignore and letting ensure_dir/1
ignore eexist will lead to people either ditching their own eexist
ignoring wrappers or start caring about ensure_dir/1's return value
now that they can use 'ok = ensure_dir(Path)'.

lib/stdlib/src/filelib.erl |    9 ++++++++-
1 files changed, 8 insertions(+), 1 deletions(-)

git fetch git://github.com/tuncer/otp.git ensure_dir_eexist

I couldn't completely agree on the indenting of nested cases
based on the rest of filelib.erl so please let me know if
this is not compliant :).

More information about the erlang-patches mailing list