Skip to content

Commit

Permalink
fixes for case-insensitive file systems
Browse files Browse the repository at this point in the history
  • Loading branch information
berquist committed Jun 10, 2024
1 parent 7e400d2 commit 694db31
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
6 changes: 3 additions & 3 deletions exdir/core/exdir_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
8 changes: 8 additions & 0 deletions exdir/core/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 694db31

Please sign in to comment.