Skip to content

Commit

Permalink
macOS is not case-sensitive by default
Browse files Browse the repository at this point in the history
  • Loading branch information
berquist committed Jun 8, 2024
1 parent c4a3079 commit ca94b98
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions exdir/core/validation.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from enum import Enum
import os
import sys
from pathlib import Path, WindowsPath
from tempfile import NamedTemporaryFile
from unicodedata import category
from . import constants as exob

Expand Down Expand Up @@ -118,7 +118,8 @@ def thorough(parent_path, name):
name_lower = name_str.lower()
_assert_valid_characters(name_lower)

if isinstance(Path(parent_path), WindowsPath):
# TODO investigate replacing with sys.platform
if not _is_fs_case_sensitive(parent_path):
# use _assert_unique if we're already on Windows, because it is much faster
# than the test below
_assert_unique(parent_path, name)
Expand All @@ -135,3 +136,13 @@ def thorough(parent_path, name):

def none(parent_path, name):
pass


def _is_fs_case_sensitive(source_dir=None):
# Adapted from https://stackoverflow.com/a/36580834/
if not hasattr(_is_fs_case_sensitive, "case_sensitive"):
with NamedTemporaryFile(prefix="TmP", dir=source_dir) as tmp_file:
setattr(_is_fs_case_sensitive,
"case_sensitive",
not os.path.exists(tmp_file.name.lower()))
return _is_fs_case_sensitive.case_sensitive

0 comments on commit ca94b98

Please sign in to comment.