On 5/23/07, Nathaniel Smith <[EMAIL PROTECTED]> wrote:
On Wed, May 23, 2007 at 03:12:55PM -0400, Ethan Blanton wrote:
> Is this true on all reasonable filesystems and operating environments?
> I know that there are flavors of Unix out there (maybe *all* flavors
> of Unix older than some age?) which will let you open() and read() a
> directory.

Well, true -- and as mentioned upthread, we might want to notice
symlinks (not to mention even nastier weird files, like fifos that
will just make us block).  So that would suggest a single stat before
opening, not 4...

There are open(2) flags to prevent all of those headaches that I can
think of (O_NOFOLLOW|O_NONBLOCK|O_NOCTTY should do it, in fact), and
it can be nearly twice as fast to do open() and then fstat() as
[l]stat and then open()... and there's no race then, either.  This
*will* open a directory or device file, but that is harmless; we just
don't try to read from it.  It won't open a symlink, which is actually
a bug in Unix (there is no race-free way to read the content of a
symlink).

Perhaps I should borrow the code I wrote for GCC, lo these many years
ago, to do just this...

zw


_______________________________________________
Monotone-devel mailing list
Monotone-devel@nongnu.org
http://lists.nongnu.org/mailman/listinfo/monotone-devel

Reply via email to