From 694db317321c4524f51968d49c0aff965fe35f12 Mon Sep 17 00:00:00 2001 From: Eric Berquist Date: Mon, 10 Jun 2024 07:42:19 -0400 Subject: [PATCH] fixes for case-insensitive file systems --- exdir/core/exdir_file.py | 6 +++--- exdir/core/validation.py | 8 ++++++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/exdir/core/exdir_file.py b/exdir/core/exdir_file.py index 9b0afc1..da4f585 100644 --- a/exdir/core/exdir_file.py +++ b/exdir/core/exdir_file.py @@ -125,11 +125,11 @@ def __init__(self, directory, mode=None, allow_remove=False, # If we have name validation, we need to check for uniqueness. The # directory may exist but with a different case, in which case we - # don't want to say that is already exists so that it matches the + # don't want to say that it already exists so that it matches the # correct checks for the requested mode. if name_validation != validation.none: - already_exists = validation.path_already_exists_case_insensitive( - str(directory.parent), directory.name.lower() + already_exists = validation.path_already_exists_case_sensitive( + str(directory.parent), directory.name ) else: already_exists = directory.exists() diff --git a/exdir/core/validation.py b/exdir/core/validation.py index 2ae1e9a..26574a7 100644 --- a/exdir/core/validation.py +++ b/exdir/core/validation.py @@ -132,3 +132,11 @@ def path_already_exists_case_insensitive(parent_path, name_lower): if name_lower == item.lower(): return True return False + + +def path_already_exists_case_sensitive(parent_path, name): + # os.listdir is much faster here than os.walk or parent_path.iterdir + for item in os.listdir(parent_path): + if name == item: + return True + return False