Fix bugs handling locked files.