diff --git a/core/lib/Drupal/Component/PhpStorage/MTimeProtectedFastFileStorage.php b/core/lib/Drupal/Component/PhpStorage/MTimeProtectedFastFileStorage.php index 3e660a0a724..ff1286baf9a 100644 --- a/core/lib/Drupal/Component/PhpStorage/MTimeProtectedFastFileStorage.php +++ b/core/lib/Drupal/Component/PhpStorage/MTimeProtectedFastFileStorage.php @@ -152,6 +152,14 @@ class MTimeProtectedFastFileStorage extends FileStorage { * Returns the full path of the containing directory where the file is or should be stored. */ protected function getContainingDirectoryFullPath($name) { + // Remove the .php file extension from the directory name. + // Within a single directory, a subdirectory cannot have the same name as a + // file. Thus, when switching between MTimeProtectedFastFileStorage and + // FileStorage, the subdirectory or the file cannot be created in case the + // other file type exists already. + if (substr($name, -4) === '.php') { + $name = substr($name, 0, -4); + } return $this->directory . '/' . str_replace('/', '#', $name); } diff --git a/core/tests/Drupal/Tests/Component/PhpStorage/MTimeProtectedFileStorageBase.php b/core/tests/Drupal/Tests/Component/PhpStorage/MTimeProtectedFileStorageBase.php index 062b857da62..46387fbf4a5 100644 --- a/core/tests/Drupal/Tests/Component/PhpStorage/MTimeProtectedFileStorageBase.php +++ b/core/tests/Drupal/Tests/Component/PhpStorage/MTimeProtectedFileStorageBase.php @@ -66,7 +66,12 @@ abstract class MTimeProtectedFileStorageBase extends PhpStorageTestBase { $name = 'simpletest.php'; $php->save($name, 'secret . $directory_mtime) . '.php';