Skip to content

Commit

Permalink
BUG Include php version in default cache folder name
Browse files Browse the repository at this point in the history
Update CoreTest.php
  • Loading branch information
JorisDebonnet authored and Damian Mooyman committed Feb 12, 2015
1 parent f8fe4a9 commit 047fe3a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
5 changes: 3 additions & 2 deletions core/TempPath.php
Expand Up @@ -64,8 +64,9 @@ function getTempParentFolder($base = null) {
}

// failing the above, try finding a namespaced silverstripe-cache dir in the system temp
$cacheFolder = DIRECTORY_SEPARATOR . 'silverstripe-cache' . str_replace(array(' ', '/', ':', '\\'), '-', $base);
$tempPath = sys_get_temp_dir() . $cacheFolder;
$tempPath = sys_get_temp_dir() . DIRECTORY_SEPARATOR .
'silverstripe-cache-php' . preg_replace('/[^\w-\.+]+/', '-', PHP_VERSION) .
str_replace(array(' ', '/', ':', '\\'), '-', $base);
if(!@file_exists($tempPath)) {
$oldUMask = umask(0);
$worked = @mkdir($tempPath, 0777);
Expand Down
28 changes: 16 additions & 12 deletions tests/core/CoreTest.php
Expand Up @@ -22,38 +22,42 @@ public function testGetTempPathInProject() {
$this->assertEquals(getTempFolder(BASE_PATH), $this->tempPath . DIRECTORY_SEPARATOR . $user);
} else {
$user = getTempFolderUsername();
$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
$this->assertEquals(sys_get_temp_dir() . DIRECTORY_SEPARATOR .
'silverstripe-cacheC--inetpub-wwwroot-silverstripe-test-project' . DIRECTORY_SEPARATOR . $user,
$this->assertEquals(
$base . 'C--inetpub-wwwroot-silverstripe-test-project' . DIRECTORY_SEPARATOR . $user,
getTempFolder('C:\\inetpub\\wwwroot\\silverstripe-test-project'));

// A typical Mac OS X location for where sites are stored
$this->assertEquals(sys_get_temp_dir() . DIRECTORY_SEPARATOR .
'silverstripe-cache-Users-joebloggs-Sites-silverstripe-test-project' . DIRECTORY_SEPARATOR . $user,
$this->assertEquals(
$base . '-Users-joebloggs-Sites-silverstripe-test-project' . DIRECTORY_SEPARATOR . $user,
getTempFolder('/Users/joebloggs/Sites/silverstripe-test-project'));

// A typical Linux location for where sites are stored
$this->assertEquals(sys_get_temp_dir() . DIRECTORY_SEPARATOR .
'silverstripe-cache-var-www-silverstripe-test-project' . DIRECTORY_SEPARATOR . $user,
$this->assertEquals(
$base . '-var-www-silverstripe-test-project' . DIRECTORY_SEPARATOR . $user,
getTempFolder('/var/www/silverstripe-test-project'));
}
}

public function tearDown() {
parent::tearDown();
$user = getTempFolderUsername();
$base = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'silverstripe-cache-php' .
preg_replace('/[^\w-\.+]+/', '-', PHP_VERSION);
foreach(array(
'silverstripe-cacheC--inetpub-wwwroot-silverstripe-test-project',
'silverstripe-cache-Users-joebloggs-Sites-silverstripe-test-project',
'silverstripe-cache-var-www-silverstripe-test-project'
'C--inetpub-wwwroot-silverstripe-test-project',
'-Users-joebloggs-Sites-silverstripe-test-project',
'-cache-var-www-silverstripe-test-project'
) as $dir) {
$path = sys_get_temp_dir().DIRECTORY_SEPARATOR.$dir;
$path = $base . $dir;
if(file_exists($path)) {
rmdir($path . DIRECTORY_SEPARATOR . $user);
rmdir($path);
}
}
}
}
}

}

0 comments on commit 047fe3a

Please sign in to comment.