diff --git a/administrator/components/com_admin/script.php b/administrator/components/com_admin/script.php index 82d08257acf8a..ce847ce0beac2 100644 --- a/administrator/components/com_admin/script.php +++ b/administrator/components/com_admin/script.php @@ -6999,7 +6999,7 @@ protected function fixFilenameCasing() $newBasename = basename($newRealpath); $expectedBasename = basename($expected); - // On Windows with incorrectly cased file. + // On Windows or Unix with only the incorrectly cased file. if ($newBasename !== $expectedBasename) { // Rename the file. @@ -7009,10 +7009,25 @@ protected function fixFilenameCasing() continue; } - // On Unix with correctly and incorrectly cased files. - if ($oldBasename === basename($old) && $newBasename === $expectedBasename) + // There might still be an incorrectly cased file on other OS than Windows. + if ($oldBasename === basename($old)) { - unlink(JPATH_ROOT . '/' . $old); + // Check if case-insensitive file system, eg on OSX. + if (fileinode($oldRealpath) === fileinode($newRealpath)) + { + // Check deeper because even realpath or glob might not return the actual case. + if (!in_array($expectedBasename, scandir(dirname($newRealpath)))) + { + // Rename the file. + rename(JPATH_ROOT . '/' . $old, JPATH_ROOT . '/' . $old . '.tmp'); + rename(JPATH_ROOT . '/' . $old . '.tmp', JPATH_ROOT . '/' . $expected); + } + } + else + { + // On Unix with both files: Delete the incorrectly cased file. + unlink(JPATH_ROOT . '/' . $old); + } } } }