file: module and character special files

Ulf Wiger ulf.wiger@REDACTED
Tue Mar 2 15:03:59 CET 2004

On Tue, 2 Mar 2004 14:37:53 +0100, Matthias Lang <matthias@REDACTED> 

> The "should file:open()" return 'eisdir' can be considered in
> political terms. You could say:
>   "The documentation says 'eisdir' only happens if the file is
>   a directory. The right way to handle the current situation is
>   to use file:read_file_info() to determine the file type rather
>   than relying on a bug.
>   Breaking backwards compatibility only punishes people who did
>   the wrong thing. So it should be done."
> But you could also argue that the role of the maintainers is to
> minimise harm, and the harm done to existing, large projects far
> outweighs the inconvenience of confused newbies.

I found the following in my own code:

%% Instead of doing read_file_info on entries to find out if they are
%% directories, we try list_dir/1 directly (saves us port comm).
%% Thus, when called with {error, enotdir}, we know that we did list_dir()
%% on a regular file, and happily move on.
sh_match({ok, Files}, [ThisPat], Root) ->
     Files1 = try_pat(Files, sh_expr(ThisPat)),
    [{Root, Files1}];
sh_match({ok, Files}, [ThisPat|Ps], Root) ->
     Files1 = try_pat(Files, sh_expr(ThisPat)),
     try_list(Files1, Ps, Root);
sh_match({error, enotdir}, _, _) ->

In principle then, I deserve to be punished for doing the Wrong Thing,
even though in this case, my code doesn't break.

However, the comment is wrong. It should obviously say "we know that
we did list_dir() on something which is not a directory"

...a chilling thought entered my mind, and I just had to check:

1> file:list_dir("/dev/null").

<sigh mode="relief"/>

/Uffe (confused newbie)

PS In my defense, I would like to add that the above code was
designed to operate in a heavily loaded ClearCase environment,
where _any_ file operation might hang for a looong time.

Ulf Wiger, Senior System Architect

This communication is confidential and intended solely for the addressee(s). Any unauthorized review, use, disclosure or distribution is prohibited. If you believe this message has been sent to you in error, please notify the sender by replying to this transmission and delete the message without disclosing it. Thank you.

E-mail including attachments is susceptible to data corruption, interruption, unauthorized amendment, tampering and viruses, and we only send and receive e-mails on the basis that we are not liable for any such corruption, interception, amendment, tampering or viruses or any consequences thereof.

More information about the erlang-questions mailing list