From b115dc3c243ea4e02e36f250bb560f11d22f18a2 Mon Sep 17 00:00:00 2001 From: Will McGugan Date: Sun, 5 May 2019 17:50:55 +0100 Subject: [PATCH] change case insensitivity test (#282) * change case insensitivity test * changelog --- CHANGELOG.md | 4 ++-- fs/osfs.py | 14 +++++++++----- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d1be3b24..a5504e2d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,7 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). -## [Unreleased] +## [2.4.5] - 2019-05-05 ### Fixed @@ -15,7 +15,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ### Changed -- Removed case_insensitive meta value from OSFS meta on OSX. normcase check doesn't work on OSX (https://stackoverflow.com/questions/7870041/check-if-file-system-is-case-insensitive-in-python) +- Detect case insensitivity using by writing temp file ## [2.4.4] - 2019-02-23 diff --git a/fs/osfs.py b/fs/osfs.py index 5877fc79..70a9f26b 100644 --- a/fs/osfs.py +++ b/fs/osfs.py @@ -17,6 +17,7 @@ import shutil import stat import sys +import tempfile import typing import six @@ -134,7 +135,6 @@ def __init__( raise errors.CreateFailed("root path does not exist") _meta = self._meta = { - "case_insensitive": os.path.normcase("Aa") == "aa", "network": False, "read_only": False, "supports_rename": True, @@ -143,10 +143,14 @@ def __init__( "virtual": False, } - if platform.system() == "Darwin": - # Standard test doesn't work on OSX. - # Best we can say is we don't know. - del _meta["case_insensitive"] + try: + # https://stackoverflow.com/questions/7870041/check-if-file-system-is-case-insensitive-in-python + # I don't know of a better way of detecting case insensitivity of a filesystem + with tempfile.NamedTemporaryFile(prefix="TmP") as _tmp_file: + _meta["case_insensitive"] = os.path.exists(_tmp_file.name.lower()) + except Exception: + if platform.system() != "Darwin": + _meta["case_insensitive"] = os.path.normcase("Aa") == "aa" if _WINDOWS_PLATFORM: # pragma: no cover _meta["invalid_path_chars"] = (