Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

Re: Flock to Rename Directory

by ELISHEVA (Prior)
on Sep 17, 2009 at 16:43 UTC ( #795930=note: print w/replies, xml ) Need Help??

in reply to Flock to Rename Directory

Using flock is not necessarily a portable or guarenteed solution - even from unix box to unix box. If the file is available to two different programs, one using flock and one not, then the non-flock using program will still be able to modify the file even though the flock-using progam locked it:

From perlport:
Not implemented (Mac OS, VMS, RISC OS, VOS).
Available only on Windows NT (not on Windows 95). (Win32)

From flock:
Two potentially non-obvious but traditional flock semantics are that it waits indefinitely until the lock is granted, and that its locks merely advisory. Such discretionary locks are more flexible, but offer fewer guarantees. This means that programs that do not also use flock may modify files locked with flock.

One advantage of swallowing the SQL bullet and using a proper DBMS is that you can be assured that all access paths to your data are using the same rules for locking. If you really can't use a proper DBMS, for whatever reason, then at least consider creating your files in a directory owned by a special purpose user. Only scripts running as that user will have access to the files and subdirectories and it will be easier to prevent scripts that don't use flock (or misuse it) from writing to the directory.

Getting this to work right and testing it may take some time. If this is a homework project or a "teach myself locking project" then enjoy the learning experience. However, if the main point of this project is to accomplish a goal for a work, personal, or volunteer project, please reconsider. In particular, if your reason for avoiding SQL is that you don't know SQL and you don't want to spend the time learning it, please reconsider. The SQL commands to add, update, and remove records from a simple one table database are not all that hard to learn. Testing the non-SQL solution is likely to take a good bit of time, possibly more than learning the SQL. More importantly, you will be able to use SQL over and over. My guess is that what you learn from writing a special purpose locking solution is unlikely to be as generally useful unless you plan to make a career out of low level file system manipulations.

Best, beth

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://795930]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (5)
As of 2020-01-24 07:59 GMT
Find Nodes?
    Voting Booth?