Skip to content

Instantly share code, notes, and snippets.

@lpgauth
Created June 26, 2014 18:57
Show Gist options
  • Save lpgauth/1445963ca3f78ce45ee1 to your computer and use it in GitHub Desktop.
Save lpgauth/1445963ca3f78ce45ee1 to your computer and use it in GitHub Desktop.
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}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment