From 68c3add93ca4758ed0ed71fcffe729f866d705cf Mon Sep 17 00:00:00 2001 From: Wes Galbraith Date: Wed, 5 Oct 2022 08:00:02 -0600 Subject: [PATCH] Change initialize_from_disk to raise FileNotFoundError when input path does not exist or is a file --- ofrak_core/ofrak/core/filesystem.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/ofrak_core/ofrak/core/filesystem.py b/ofrak_core/ofrak/core/filesystem.py index f86fe730e..2f8cde33e 100644 --- a/ofrak_core/ofrak/core/filesystem.py +++ b/ofrak_core/ofrak/core/filesystem.py @@ -276,6 +276,16 @@ async def initialize_from_disk( path: str, ): root_path = os.path.normpath(path) + + if not os.path.exists(root_path): + raise FileNotFoundError( + f"Could not initialize from disk. Root path does not exist: {root_path}" + ) + if not os.path.isdir(root_path): + raise FileNotFoundError( + f"Could not initialize from disk. Found a file instead of a directory: {root_path}" + ) + for root, dirs, files in os.walk(root_path): for d in sorted(dirs): absolute_path = os.path.join(root, d)