From a990c99d6e6f477ab6e973ada13f9dff234682f5 Mon Sep 17 00:00:00 2001 From: Lukas Date: Fri, 16 Jun 2017 01:25:02 +0200 Subject: [PATCH] NEW: suffix subfolder in silverstripe-cache with php-version (#6810) Note that this changes the default temp path value * Was: /tmp/silverstripe-cache-Users-FOO-webroot-BAR-php7.1.5/USER * Now: /tmp/silverstripe-cache-Users-FOO-webroot-BAR/USER-php7.1.5 --- core/TempPath.php | 7 ++++--- tests/core/CoreTest.php | 22 ++++++++++------------ 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/core/TempPath.php b/core/TempPath.php index 88979baa4..4f3a94c85 100644 --- a/core/TempPath.php +++ b/core/TempPath.php @@ -11,8 +11,9 @@ function getTempFolder($base = null) { $parent = getTempParentFolder($base); - // The actual temp folder is a subfolder of getTempParentFolder(), named by username - $subfolder = $parent . DIRECTORY_SEPARATOR . getTempFolderUsername(); + // The actual temp folder is a subfolder of getTempParentFolder(), named by username and suffixed with currently used php-version + $phpversion = '-php' . preg_replace('/[^\w-\.+]+/', '-', PHP_VERSION); + $subfolder = $parent . DIRECTORY_SEPARATOR . getTempFolderUsername() . $phpversion; if(!@file_exists($subfolder)) { mkdir($subfolder); @@ -64,7 +65,7 @@ function getTempParentFolder($base = null) { // failing the above, try finding a namespaced silverstripe-cache dir in the system temp $tempPath = sys_get_temp_dir() . DIRECTORY_SEPARATOR . - 'silverstripe-cache-php' . preg_replace('/[^\w-\.+]+/', '-', PHP_VERSION) . + 'silverstripe-cache' . str_replace(array(' ', '/', ':', '\\'), '-', $base); if(!@file_exists($tempPath)) { $oldUMask = umask(0); diff --git a/tests/core/CoreTest.php b/tests/core/CoreTest.php index 7e7915492..5b4cc7510 100644 --- a/tests/core/CoreTest.php +++ b/tests/core/CoreTest.php @@ -17,27 +17,25 @@ class CoreTest extends SapphireTest { public function testGetTempPathInProject() { $user = getTempFolderUsername(); - + $phpversion = '-php' . preg_replace('/[^\w-\.+]+/', '-', PHP_VERSION); if(file_exists($this->tempPath)) { - $this->assertEquals(getTempFolder(BASE_PATH), $this->tempPath . DIRECTORY_SEPARATOR . $user); + $this->assertEquals(getTempFolder(BASE_PATH), $this->tempPath . DIRECTORY_SEPARATOR . $user . $phpversion); } else { - $user = getTempFolderUsername(); - $base = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'silverstripe-cache-php' . - preg_replace('/[^\w-\.+]+/', '-', PHP_VERSION); + $base = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'silverstripe-cache'; // A typical Windows location for where sites are stored on IIS $this->assertEquals( - $base . 'C--inetpub-wwwroot-silverstripe-test-project' . DIRECTORY_SEPARATOR . $user, + $base . 'C--inetpub-wwwroot-silverstripe-test-project' . DIRECTORY_SEPARATOR . $user . $phpversion, getTempFolder('C:\\inetpub\\wwwroot\\silverstripe-test-project')); // A typical Mac OS X location for where sites are stored $this->assertEquals( - $base . '-Users-joebloggs-Sites-silverstripe-test-project' . DIRECTORY_SEPARATOR . $user, + $base . '-Users-joebloggs-Sites-silverstripe-test-project' . DIRECTORY_SEPARATOR . $user . $phpversion, getTempFolder('/Users/joebloggs/Sites/silverstripe-test-project')); // A typical Linux location for where sites are stored $this->assertEquals( - $base . '-var-www-silverstripe-test-project' . DIRECTORY_SEPARATOR . $user, + $base . '-var-www-silverstripe-test-project' . DIRECTORY_SEPARATOR . $user . $phpversion, getTempFolder('/var/www/silverstripe-test-project')); } } @@ -45,8 +43,9 @@ class CoreTest extends SapphireTest { public function tearDown() { parent::tearDown(); $user = getTempFolderUsername(); - $base = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'silverstripe-cache-php' . - preg_replace('/[^\w-\.+]+/', '-', PHP_VERSION); + $phpversion = '-php' . preg_replace('/[^\w-\.+]+/', '-', PHP_VERSION); + $base = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'silverstripe-cache' . $phpversion; + foreach(array( 'C--inetpub-wwwroot-silverstripe-test-project', '-Users-joebloggs-Sites-silverstripe-test-project', @@ -54,10 +53,9 @@ class CoreTest extends SapphireTest { ) as $dir) { $path = $base . $dir; if(file_exists($path)) { - rmdir($path . DIRECTORY_SEPARATOR . $user); + rmdir($path . DIRECTORY_SEPARATOR . $user . $phpversion); rmdir($path); } } } - }