Fix various locking issues

- When a file no longer exists (delete, rename), clean the lock object
- Don't hold existing file handles open in the lock object
- Fix infinite loop when trying to get a read lock on a file that has been write locked

cc @th3fallen @PVince81 @DeepDiver1975