[erlang-questions] Reading a file before it has been completely written

David Mercer dmercer@REDACTED
Wed Mar 7 19:08:44 CET 2012


On Wednesday, March 07, 2012, Richard Carlsson wrote:

> Hey, a user! I haven't had any reports about this module before (and
> the
> fact that it's still in my development branch of eunit is more of a
> historical accident; it's not shipped with OTP). I don't know of any
> real issues with it though.

It works fine.  If you know of a better one, I'd be OK switching.  This was
just the one that came up when I Googled.

> In this case, I think the problem is just the underlying file system
> semantics. I presume it's Linux, and in Unix:y file systems a file can
> be seen to exist and can be opened for reading as soon as it has been
> created. Trying to fiddle with exclusive locks is probably always going
> to have corner cases. The only techniques you can trust to practically
> always work and be portable across file systems are directory creation
> and file renaming. So what Tony suggested is likely to be the best
> solution: create the file under another name or in a separate
> directory,
> and when it's completely written, rename it.

I might go back to my renaming approach, which also had no failures during
testing.  I just attempt to rename the file to itself.  If it fails, I try
again 5 seconds later.

Thanks.

Cheers,

DBM




More information about the erlang-questions mailing list