Fix #32775 if permission denined, `prepareForReplaceOrAdd` will return nothing, and this case is not handled.