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
This commit is contained in:
Lukas 2017-06-16 01:25:02 +02:00 committed by Sam Minnée
parent 273a087f5a
commit a990c99d6e
2 changed files with 14 additions and 15 deletions

View File

@ -11,8 +11,9 @@
function getTempFolder($base = null) { function getTempFolder($base = null) {
$parent = getTempParentFolder($base); $parent = getTempParentFolder($base);
// The actual temp folder is a subfolder of getTempParentFolder(), named by username // The actual temp folder is a subfolder of getTempParentFolder(), named by username and suffixed with currently used php-version
$subfolder = $parent . DIRECTORY_SEPARATOR . getTempFolderUsername(); $phpversion = '-php' . preg_replace('/[^\w-\.+]+/', '-', PHP_VERSION);
$subfolder = $parent . DIRECTORY_SEPARATOR . getTempFolderUsername() . $phpversion;
if(!@file_exists($subfolder)) { if(!@file_exists($subfolder)) {
mkdir($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 // failing the above, try finding a namespaced silverstripe-cache dir in the system temp
$tempPath = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $tempPath = sys_get_temp_dir() . DIRECTORY_SEPARATOR .
'silverstripe-cache-php' . preg_replace('/[^\w-\.+]+/', '-', PHP_VERSION) . 'silverstripe-cache' .
str_replace(array(' ', '/', ':', '\\'), '-', $base); str_replace(array(' ', '/', ':', '\\'), '-', $base);
if(!@file_exists($tempPath)) { if(!@file_exists($tempPath)) {
$oldUMask = umask(0); $oldUMask = umask(0);

View File

@ -17,27 +17,25 @@ class CoreTest extends SapphireTest {
public function testGetTempPathInProject() { public function testGetTempPathInProject() {
$user = getTempFolderUsername(); $user = getTempFolderUsername();
$phpversion = '-php' . preg_replace('/[^\w-\.+]+/', '-', PHP_VERSION);
if(file_exists($this->tempPath)) { 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 { } else {
$user = getTempFolderUsername(); $base = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'silverstripe-cache';
$base = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'silverstripe-cache-php' .
preg_replace('/[^\w-\.+]+/', '-', PHP_VERSION);
// A typical Windows location for where sites are stored on IIS // A typical Windows location for where sites are stored on IIS
$this->assertEquals( $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')); getTempFolder('C:\\inetpub\\wwwroot\\silverstripe-test-project'));
// A typical Mac OS X location for where sites are stored // A typical Mac OS X location for where sites are stored
$this->assertEquals( $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')); getTempFolder('/Users/joebloggs/Sites/silverstripe-test-project'));
// A typical Linux location for where sites are stored // A typical Linux location for where sites are stored
$this->assertEquals( $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')); getTempFolder('/var/www/silverstripe-test-project'));
} }
} }
@ -45,8 +43,9 @@ class CoreTest extends SapphireTest {
public function tearDown() { public function tearDown() {
parent::tearDown(); parent::tearDown();
$user = getTempFolderUsername(); $user = getTempFolderUsername();
$base = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'silverstripe-cache-php' . $phpversion = '-php' . preg_replace('/[^\w-\.+]+/', '-', PHP_VERSION);
preg_replace('/[^\w-\.+]+/', '-', PHP_VERSION); $base = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'silverstripe-cache' . $phpversion;
foreach(array( foreach(array(
'C--inetpub-wwwroot-silverstripe-test-project', 'C--inetpub-wwwroot-silverstripe-test-project',
'-Users-joebloggs-Sites-silverstripe-test-project', '-Users-joebloggs-Sites-silverstripe-test-project',
@ -54,10 +53,9 @@ class CoreTest extends SapphireTest {
) as $dir) { ) as $dir) {
$path = $base . $dir; $path = $base . $dir;
if(file_exists($path)) { if(file_exists($path)) {
rmdir($path . DIRECTORY_SEPARATOR . $user); rmdir($path . DIRECTORY_SEPARATOR . $user . $phpversion);
rmdir($path); rmdir($path);
} }
} }
} }
} }