Raise error if lockfile name is taken by non-lockfile
Hello,
First of all, thanks a lot for putting this module together, and apologies in advance if this is not the best place to raise this or if this is a conscious design choice on your part. However, it took me a trip through the source code of flufl/lock/_lockfile.py to figure out what was going wrong with my code.
The Lock class uses the value of the 'lockfile' argument which must be a) distinct from the name of the file that's being locked, and b) distinct from any other file already present in the system. However, no checks are performed to make sure that this is the case, and I did not find this mentioned in the documentation.
If 'lockfile' points to an existing file, its contents can be overwritten when the lock is acquired, and they will be deleted when the lock is released ("unlock"ed), by virtue os.unlink(self._lockfile)
on line 402 in _lockfile.py. This is especially evident when using "with lock: ...", which bypasses several types of errors and attempts to release the lock at the end of the code block in almost every scenario.
I'm running my code using a dockerized NFS server in Kubernetes on MX Linux, but I strongly suspect this issue will arise in many/all setups.
Thank you for your time, and have a great day!