From d95162259c94412df041482c27f951b038523b05 Mon Sep 17 00:00:00 2001 From: Garvin Hicking Date: Thu, 16 Nov 2023 12:24:27 +0100 Subject: [PATCH] [BUGFIX] Check Document EntryRoot respecting case sensitivity on macOS (#677) * [BUGFIX] Check Document entry root by respecting case sensitivity on macOS On macOS filesystems, a file-check against "index.rst" using $filesystem->has() would return TRUE, when in fact a file might be stored as "Index.rst". Thus, at this point we fetch the whole directory list and compare the contents with if the INDEX_FILE_NAMES entry matches. This ensures that we get the file with exactly the casing that is returned from the filesystem. Background: Given a file called "Index.rst" exists on macOS, executing this script: ``` has() would return TRUE, when in fact + // a file might be stored as "Index.rst". Thus, at this point + // we fetch the whole directory list and compare the contents + // with if the INDEX_FILE_NAMES entry matches. This ensures + // that we get the file with exactly the casing that is returned + // from the filesystem. + $contentFromFilesystem = $filesystem->listContents($directory); + $hashedContentFromFilesystem = []; + foreach ($contentFromFilesystem as $itemFromFilesystem) { + $hashedContentFromFilesystem[$itemFromFilesystem['basename']] = true; + } + foreach (self::INDEX_FILE_NAMES as $indexName) { $indexFilename = sprintf('%s.%s', $indexName, $extension); - if ($filesystem->has($directory . '/' . $indexFilename)) { + if (isset($hashedContentFromFilesystem[$indexFilename])) { return $indexName; } }