On Tue, 13 Sep 2005, Morgan wrote:

> Jim Freeze wrote:
>> This may be off topic, but I always wonder why all the flags to File.
>> Could what you are doing be written as:
>> 
>>   File.open(ARGV[1], "w") { |outfile|
>>     File.foreach(ARGV[0]) { |line|
>>       outfile.puts CGI::unescapeHTML(line)
>>     }
>>   }
>> 
>> or am I missing something big here?
>
> Well, in this case, I don't believe it's possible to
> get the effect of File::EXCL (which basically amounts to
> "don't overwrite an existing file") with a string as the open
> mode. There are some other combinations of parameters
> that are also difficult (impossible) to achieve that way.
> (I don't remember exactly what it was, but I think it had to
> do with a file that was being opened for reading and writing.
> All the strings I tried either wouldn't let me access parts of
> an existing file, or otherwise failed to perfrom as I required.)

O_EXCL is broken on nfs:

   O_EXCL When used with O_CREAT, if the file  already  exists  it  is  an error
   and  the open will fail. In this context, a symbolic link exists, regardless of
   where its points to.  O_EXCL is broken  on NFS file systems, programs which
   rely on it for performing lock- ing tasks will contain a race condition.  The
   solution for  per- forming  atomic  file  locking  using  a lockfile is to
   create a unique file on the same fs  (e.g.,  incorporating  hostname  and pid),
   use  link(2)  to  make  a link to the lockfile. If link() returns 0, the lock
   is successful.  Otherwise,  use  stat(2)  on the  unique  file to check if its
   link count has increased to 2, in which case the lock is also successful.


fyi.

-a
-- 
===============================================================================
| email :: ara [dot] t [dot] howard [at] noaa [dot] gov
| phone :: 303.497.6469
| Your life dwells amoung the causes of death
| Like a lamp standing in a strong breeze.  --Nagarjuna
===============================================================================