Fix warnings when locking the file if directory doesn't exist