Fix locking to not delete file unless lock was obtained