Re: How to tell if a file is busy?
Re: How to tell if a file is busy?
- Subject: Re: How to tell if a file is busy?
- From: Chris Page <email@hidden>
- Date: Thu, 27 Sep 2001 17:44:58 -0700
nigh on 2001.09.27 12:07 PM, Doug McNutt at email@hidden wrote:
>
Some time ago I was trying to wait until Netscape had downloaded a
>
document into a file using https. I used a variety of techniques,
>
AppleScript, MacPerl, attempting to wait by repeatedly attempting to
>
open the file for write access expecting the open to fail until
>
Netscape was finished. It doesn't work. The system allows both
>
applications to have the file open without complaint. Other browsers
>
have the same problem and no browser returns a result.
A file can be opened for read access multiple times, from within the same or
different processes at the same time. Only one process can open a given file
with write access, however. If the browser keeps the file open for write,
you'll be able to read it, but you won't be able to write it. So you might
try opening a file with write access to see if the browser is done writing
it.
Unfortunately, as I mentioned elsewhere, on Mac OS X although a given file
can only be opened once with write access within a given process, multiple
processes can open the file with write access (they can't tell the file is
busy in another process, either), so you can no longer rely on checking
whether the file is "busy" to control access to a file. I guess this
reflects the underlying BSD I/O model, but it seems ludicrously stupid and
burdensome to me. It means programs have to find some more complicated way
to share access to a file, and of course you can only do this between
cooperating programs -- any program that doesn't participate in your
necessarily proprietary scheme may ruin your day.
--
Chris Page
Mac OS Lead, Palm Desktop
Palm, Inc.
One of the symptoms of an approaching nervous breakdown is the belief that
one's work is a giant talking wheel of cheese. - Bertell Russland