From 9ac547d32d53ed2249fb47d8c3e4efc13a2edaab Mon Sep 17 00:00:00 2001 From: Sam Minnee Date: Thu, 28 Jan 2010 05:10:32 +0000 Subject: [PATCH] BUGFIX: Don't rely on the current working directory for any file access; use BASE_PATH. git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.4@97728 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- conf/ConfigureFromEnv.php | 2 +- core/Core.php | 24 +++++++++++++----------- core/control/ContentController.php | 6 +++--- dev/SapphireInfo.php | 2 +- dev/TestRunner.php | 2 +- filesystem/TarballArchive.php | 3 ++- tests/PhpSyntaxTest.php | 2 +- tests/filesystem/FileTest.php | 8 ++++---- 8 files changed, 26 insertions(+), 23 deletions(-) diff --git a/conf/ConfigureFromEnv.php b/conf/ConfigureFromEnv.php index 45d85f1dd..17637f132 100644 --- a/conf/ConfigureFromEnv.php +++ b/conf/ConfigureFromEnv.php @@ -98,5 +98,5 @@ if(defined('SS_USE_BASIC_AUTH') && SS_USE_BASIC_AUTH) { } if(defined('SS_ERROR_LOG')) { - SS_Log::add_writer(new SS_LogFileWriter('../' . SS_ERROR_LOG), SS_Log::WARN, '<='); + SS_Log::add_writer(new SS_LogFileWriter(BASE_PATH . '/' . SS_ERROR_LOG), SS_Log::WARN, '<='); } diff --git a/core/Core.php b/core/Core.php index 737f12ced..8d10f63c2 100755 --- a/core/Core.php +++ b/core/Core.php @@ -155,6 +155,19 @@ increase_memory_limit_to('64M'); /////////////////////////////////////////////////////////////////////////////// // INCLUDES +/** + * Add sapphire/parsers and sapphire/thirdparty include paths, as well as adding a fixed reference + * to BASEPATH/sapphrie in case we chdir() + */ + +// Add after the "." path but before other paths (so that they take precedence over the PEAR +// include paths) +set_include_path(str_replace('.' . PATH_SEPARATOR, '.' . PATH_SEPARATOR + . BASE_PATH . '/sapphire' . PATH_SEPARATOR + . BASE_PATH . '/sapphire/parsers' . PATH_SEPARATOR + . BASE_PATH . '/sapphire/thirdparty' . PATH_SEPARATOR + , get_include_path())); + require_once("core/ManifestBuilder.php"); require_once("core/ClassInfo.php"); require_once('core/Object.php'); @@ -162,17 +175,6 @@ require_once('core/control/Director.php'); require_once('filesystem/Filesystem.php'); require_once("core/Session.php"); -/** - * Add sapphire/parsers and sapphire/thirdparty include paths - */ - -// Add after the "." path but before other paths (so that they take precedence over the PEAR -// include paths) -set_include_path(str_replace('.' . PATH_SEPARATOR, '.' . PATH_SEPARATOR - . BASE_PATH . '/sapphire/parsers' . PATH_SEPARATOR - . BASE_PATH . '/sapphire/thirdparty' . PATH_SEPARATOR - , get_include_path())); - /////////////////////////////////////////////////////////////////////////////// // MANIFEST diff --git a/core/control/ContentController.php b/core/control/ContentController.php index 22fbb1f58..25e0a99c0 100755 --- a/core/control/ContentController.php +++ b/core/control/ContentController.php @@ -499,11 +499,11 @@ HTML ); foreach($installfiles as $installfile) { - if(file_exists('../' . $installfile)) { - @unlink('../' . $installfile); + if(file_exists(BASE_PATH . '/' . $installfile)) { + @unlink(BASE_PATH . '/' . $installfile); } - if(file_exists('../' . $installfile)) { + if(file_exists(BASE_PATH . '/' . $installfile)) { $unsuccessful[] = $installfile; } } diff --git a/dev/SapphireInfo.php b/dev/SapphireInfo.php index f9102eeb2..69dd0e79e 100644 --- a/dev/SapphireInfo.php +++ b/dev/SapphireInfo.php @@ -17,7 +17,7 @@ class SapphireInfo extends Controller { } function Version() { - $sapphireVersionFile = file_get_contents('../sapphire/silverstripe_version'); + $sapphireVersionFile = file_get_contents(BASE_PATH . '/sapphire/silverstripe_version'); if(strstr($sapphireVersionFile, "/sapphire/trunk")) { $sapphireVersion = "trunk"; diff --git a/dev/TestRunner.php b/dev/TestRunner.php index bd05de09e..bd4ead6a0 100644 --- a/dev/TestRunner.php +++ b/dev/TestRunner.php @@ -309,7 +309,7 @@ HTML; $fixtureFile = $_GET['fixture']; // Validate fixture file - $realFile = realpath('../' . $fixtureFile); + $realFile = realpath(BASE_PATH.'/'.$fixtureFile); $baseDir = realpath(Director::baseFolder()); if(!$realFile || !file_exists($realFile)) { return "

Fixture file doesn't exist

"; diff --git a/filesystem/TarballArchive.php b/filesystem/TarballArchive.php index f8113496c..2b5a7c18f 100644 --- a/filesystem/TarballArchive.php +++ b/filesystem/TarballArchive.php @@ -22,7 +22,8 @@ class TarballArchive extends Archive { function listing() { // Call tar on the command line to get the info we need - $command = "tar -tv{$this->compressionModifiers}f ../$this->filename"; + $base = BASE_PATH; + $command = "tar -tv{$this->compressionModifiers}f $base/$this->filename"; $consoleList = `$command`; $listing = array(); diff --git a/tests/PhpSyntaxTest.php b/tests/PhpSyntaxTest.php index 5fb982de7..8128799aa 100644 --- a/tests/PhpSyntaxTest.php +++ b/tests/PhpSyntaxTest.php @@ -17,7 +17,7 @@ class PhpSyntaxTest extends SapphireTest { $settingTests = array('short_open_tag=Off','short_open_tag=On -d asp_tags=On'); $files = $this->getAllFiles('php'); - $files[] = '../sapphire/dev/install/config-form.html'; + $files[] = BASE_PATH.'/sapphire/dev/install/config-form.html'; foreach($files as $i => $file) { $CLI_file = escapeshellarg($file); diff --git a/tests/filesystem/FileTest.php b/tests/filesystem/FileTest.php index 9da2db290..1c03d2486 100644 --- a/tests/filesystem/FileTest.php +++ b/tests/filesystem/FileTest.php @@ -103,14 +103,14 @@ class FileTest extends SapphireTest { $fileIDs = $this->allFixtureIDs('Folder'); foreach($fileIDs as $fileID) { $file = DataObject::get_by_id('Folder', $fileID); - if(!file_exists("../$file->Filename")) mkdir("../$file->Filename"); + if(!file_exists(BASE_PATH."/$file->Filename")) mkdir(BASE_PATH."/$file->Filename"); } /* Create a test files for each of the fixture references */ $fileIDs = $this->allFixtureIDs('File'); foreach($fileIDs as $fileID) { $file = DataObject::get_by_id('File', $fileID); - $fh = fopen("../$file->Filename", "w"); + $fh = fopen(BASE_PATH."/$file->Filename", "w"); fwrite($fh, str_repeat('x',1000000)); fclose($fh); } @@ -121,14 +121,14 @@ class FileTest extends SapphireTest { $fileIDs = $this->allFixtureIDs('File'); foreach($fileIDs as $fileID) { $file = DataObject::get_by_id('File', $fileID); - if(file_exists("../$file->Filename")) unlink("../$file->Filename"); + if(file_exists(BASE_PATH."/$file->Filename")) unlink(BASE_PATH."/$file->Filename"); } /* Remove the test folders that we've crated */ $fileIDs = $this->allFixtureIDs('Folder'); foreach($fileIDs as $fileID) { $file = DataObject::get_by_id('Folder', $fileID); - if(file_exists("../$file->Filename")) rmdir("../$file->Filename"); + if(file_exists(BASE_PATH."/$file->Filename")) rmdir(BASE_PATH."/$file->Filename"); } parent::tearDown();