[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] file locking




>  * Other Mac apps will not respect a LOCK_EX, but other MacPerls or other
>MacPerl threads would.  ^^^
>
Why not? I suppose because UNIX does it that way? In the previous tests the
finder was locked out with chmod(0444, $file); ie it set the locked box in
the get info dialog. So other programs may not write unless they unlock it
first. There is another finder flag for "file in use" that may be a better
match to "advisory" flock. Moreover both flags should be used.

The following errors might be appropriate for MacOS "real" locking:
flock("$filename", LOCK_EX, [LOCK_NB]) - block(wait), set the lock
bit(pass), or fail if:
   EBADF - file descriptor invalid
   EINVAL - operation invalid
   EOPNOTSUPP - file descriptor refers to object which is not a file
   [EWOULDBLOCK] - finder reports file is locked, but you specifyed LOCK_NB
   EFILEINUSE - finder reports file is in use (someone is reading that file)
   ERESOURCESLOCKED - finder reports resources of this file are locked
   EFILEPROTECTED - finder reports file is protected

flock("$filename", LOCK_SH) - set the "file in use" bit or fail if:
   EBADF - file descriptor invalid
   EINVAL - operation invalid
   EOPNOTSUPP - file descriptor refers to object which is not a file

flock("$filename", LOCK_UN) - clear the lock bit if I have rights or fail if:
   EBADF - file descriptor invalid
   EINVAL - operation invalid
   EOPNOTSUPP - file descriptor refers to object which is not a file
   EFILEPROTECTED - finder reports file is protected
   ENOPRIVLEDGES - you do not have rights to unlock
   EWASNOTLOCKED - finder reports the file was not previously locked

Rights would be determined by a Flock:: package global hash that registers
filenames that have
been flocked by you. ( A flock object would be a scaler with the
filename.The global hash would save the object references. ) So you could
specifically LOCK_UN or let the corresponding eval("END {chmod 0666,
'$file'}"); statements do them automatically when you program ends. Other
programs always have unlock rights so if MacPerl dies your not stuck. But
at least this maps the flock function into MacPerl. In all the forms I know
of anyway.

I also suppose one could make the Flock:: global hash a persistant store
that has full flock records like UNIX.



--
Fred Giorgi <mailto:fgiorg@atl.com>




***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch