[Overview][Procedures and functions] | Reference for unit 'fileshare' (#powtils_main) |
If users are going to be writing and reading to a file at the same time, should also lock the file before reading and unlock the file after finishing reading. This is so that read/write conflicts do not occur. It may seem natural only to lock a file before writing to it, however you should lock a file before reading.
You should only worry about locking files for read/write if you are going to have more than one person writing and reading at the same time - for example a wiki system that allows multiple users to update the same file on the hard drive. If the wiki is database driven, you would not need to worry about file locking as the database handles multiple communications.
The fileshare unit will be updated in future releases, or an alternative fileshare2 unit will be added and stress tested. Operating system fLock() and LockFile() routines are most likely going to be used in the next fileshare2 unit. The current fileshare unit uses code from the 1.4.x branch which the current Powtils maintainer did not write nor recommends using on busy servers or mission critical applications.
That being said, a web forum and a content manager have been written using the fileshare routines and have been running for a few years without too many problems other than occasional dangling lfw/lfr lock files once every 10 months or so.
We are also looking for developers to look over our file sharing routines and see if the garbage collector can be improved on the lfr/lfw files since sharing is a tough to get perfectly right. On really important mission critical applications, it is recommend you use a database since databases share data across thousands of users better than files. For simple and small wiki's or text files and simpler programs, file sharing can be really handy though.