`is_dir` seems to already check for the existence of $path, you can just return true here and save some network requests