Skip to content

Commit

Permalink
Error handling for dir creation
Browse files Browse the repository at this point in the history
  • Loading branch information
forefy committed Feb 13, 2024
1 parent acc6980 commit f5bb16e
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions eburger/utils/filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,24 +96,31 @@ def create_directory_if_not_exists(directory_path: Path):
# Check if the directory already exists
if not os.path.exists(directory_path):
# Create the directory
os.makedirs(directory_path)
log("debug", f"Created directory: {directory_path}")
try:
os.makedirs(directory_path)
log("debug", f"Created directory: {directory_path}")
except Exception as e:
log("error", f"Could not create direction {directory_path}. {e}")


def create_or_empty_directory(directory_path: Path):
# Check if the directory already exists
if os.path.exists(directory_path):
# Empty the directory by removing all its contents
shutil.rmtree(directory_path)
os.makedirs(directory_path)
log(
"debug",
f"Emptied and re-created directory: {directory_path}",
)

try:
os.makedirs(directory_path)
log("debug", f"Emptied and re-created directory: {directory_path}")
except Exception as e:
log("error", f"Could not create direction {directory_path}. {e}")
else:
# Create the directory if it does not exist
os.makedirs(directory_path)
log("debug", f"Created directory: {directory_path}")
try:
os.makedirs(directory_path)
log("debug", f"Created directory: {directory_path}")
except Exception as e:
log("error", f"Could not create direction {directory_path}. {e}")


# TODO: Add better handling for multiple build info files
Expand Down

0 comments on commit f5bb16e

Please sign in to comment.