mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
5779097939
Anyone who has run "sudo -u www-data ./framework/sake dev/build" knows that SilverStripe's temp folder permissions can be very brittle. This patch resolves this by making the temp folder user-specific. To minimise directory pollution it first creates a chmod 777 parent folder with the same name as the current folder. It then creates a subfolder of this with the same name as the current user. The positive impact of this change is that sake can be used without fear of messing up file permissions. This means, among other things, that we can put a Composer post-update-cmd into the installer to run dev/build. Progress! The negative impact is that you will get two caches if you run sake as a different user. However, that is much better than the current situation - which is a bunch of bugs - and if you're concerned about that, you still have the option of running sake as www-data.
56 lines
2.3 KiB
PHP
56 lines
2.3 KiB
PHP
<?php
|
|
/**
|
|
* Tests for the core of SilverStripe, such as how the temporary
|
|
* directory is determined throughout the framework.
|
|
*
|
|
* @package framework
|
|
* @subpackage tests
|
|
*/
|
|
class CoreTest extends SapphireTest {
|
|
|
|
protected $tempPath;
|
|
|
|
public function setUp() {
|
|
parent::setUp();
|
|
$this->tempPath = Director::baseFolder() . '/silverstripe-cache';
|
|
}
|
|
|
|
public function testGetTempPathInProject() {
|
|
if(file_exists($this->tempPath)) {
|
|
$this->assertEquals(getTempFolder(BASE_PATH), $this->tempPath);
|
|
} else {
|
|
$user = getTempFolderUsername();
|
|
|
|
// A typical Windows location for where sites are stored on IIS
|
|
$this->assertEquals(sys_get_temp_dir() . '/silverstripe-cacheC--inetpub-wwwroot-silverstripe-test-project/' . $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() . '/silverstripe-cache-Users-joebloggs-Sites-silverstripe-test-project/' . $user,
|
|
getTempFolder('/Users/joebloggs/Sites/silverstripe-test-project'));
|
|
|
|
// A typical Linux location for where sites are stored
|
|
$this->assertEquals(sys_get_temp_dir() . '/silverstripe-cache-var-www-silverstripe-test-project/' . $user,
|
|
getTempFolder('/var/www/silverstripe-test-project'));
|
|
}
|
|
}
|
|
|
|
public function tearDown() {
|
|
parent::tearDown();
|
|
$user = getTempFolderUsername();
|
|
if(file_exists(sys_get_temp_dir() . '/silverstripe-cacheC--inetpub-wwwroot-silverstripe-test-project')) {
|
|
rmdir(sys_get_temp_dir() . '/silverstripe-cacheC--inetpub-wwwroot-silverstripe-test-project/' . $user);
|
|
rmdir(sys_get_temp_dir() . '/silverstripe-cacheC--inetpub-wwwroot-silverstripe-test-project');
|
|
}
|
|
if(file_exists(sys_get_temp_dir() . '/silverstripe-cache-Users-joebloggs-Sites-silverstripe-test-project')) {
|
|
rmdir(sys_get_temp_dir() . '/silverstripe-cache-Users-joebloggs-Sites-silverstripe-test-project/' . $user);
|
|
rmdir(sys_get_temp_dir() . '/silverstripe-cache-Users-joebloggs-Sites-silverstripe-test-project');
|
|
}
|
|
if(file_exists(sys_get_temp_dir() . '/silverstripe-cache-var-www-silverstripe-test-project')) {
|
|
rmdir(sys_get_temp_dir() . '/silverstripe-cache-var-www-silverstripe-test-project/' . $user);
|
|
rmdir(sys_get_temp_dir() . '/silverstripe-cache-var-www-silverstripe-test-project');
|
|
}
|
|
}
|
|
|
|
}
|