[erlang-bugs] filelib:ensure_dir/1 broken with symlinks

Louis-Philippe Gauthier <>
Fri Jun 27 18:41:25 CEST 2014


Hi,
I'm using this patch which seems to fix my issue.

--- lib/stdlib/src/filelib.erl 2014-06-27 12:18:40.000000000 -0400
+++ lib/stdlib/src/filelib.erl 2014-06-27 12:19:22.000000000 -0400
@@ -227,7 +227,7 @@
     ok;
 ensure_dir(F) ->
     Dir = filename:dirname(F),
-    case do_is_dir(Dir, file) of
+    case do_is_dir(Dir, directory) of
  true ->
     ok;
  false when Dir =:= F ->
@@ -487,6 +487,8 @@
 badpattern(Reason) ->
     error({badpattern,Reason}).

+eval_read_file_info(File, directory) ->
+    file:read_file_info(File);
 eval_read_file_info(File, file) ->
     file:read_link_info(File);
 eval_read_file_info(File, erl_prim_loader) ->



On Fri, Jun 27, 2014 at 6:01 AM, Louis-Philippe Gauthier <
> wrote:

> filelib:ensure_dir/1 is broken when there's a symlink in the path.
>
> the offending commit:
>
>
> https://github.com/erlang/otp/commit/f11aabdc9fec593c31e6c4f3fa25c1707e9c35df
>
> e.g.
>
> ~ $ mkdir test
> ~ $ ln -s test test2
>
> ~ $ erl
> Erlang/OTP 17 [erts-6.1] [source] [64-bit] [smp:4:4] [async-threads:10]
> [hipe] [kernel-poll:false] [dtrace]
>
> Eshell V6.1  (abort with ^G)
> 1> filelib:ensure_dir("test2/foo").
> {error,eexist}
>
> 2> file:make_dir("test2").
> {error,eexist}
>
> This happens because eval_read_file_info/2 uses read_link_info/1 instead
> of read_file_info/1. The file_info type is link instead of folder.
>
> Since it really is a folder, it fails to create the new folder with
> {error, eexist}.
>
> 3> file:read_link_info("test2").
> {ok,{file_info,5,symlink,read_write,
>                {{2014,6,26},{14,52,45}},
>                {{2014,6,26},{14,52,45}},
>                {{2014,6,26},{14,52,45}},
>                41453,1,16777220,0,55514582,501,20}}
>
> vs
>
> 4> file:read_file_info("test2").
> {ok,{file_info,102,directory,read_write,
>                {{2014,6,26},{14,53,26}},
>                {{2014,6,26},{14,53,32}},
>                {{2014,6,26},{14,53,32}},
>                16877,3,16777220,0,55514786,501,20}}
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-bugs/attachments/20140627/1aa9e794/attachment.html>


More information about the erlang-bugs mailing list