Fix some bugs in locked file handling.