Permalink
Browse files

Consistently use the $base argument to getTempFolder()

  • Loading branch information...
1 parent e509fb5 commit aa4fa750910b16212e62fe1ceb0838dd23231414 @halkyon halkyon committed Sep 19, 2012
Showing with 16 additions and 20 deletions.
  1. +16 −20 core/Core.php
View
@@ -304,37 +304,33 @@ function getSysTempDir() {
/**
* Returns the temporary folder that silverstripe should use for its cache files
* This is loaded into the TEMP_FOLDER define on start up
- *
+ *
* @param $base The base path to use as the basis for the temp folder name. Defaults to BASE_PATH,
* which is usually fine; however, the $base argument can be used to help test.
*/
function getTempFolder($base = null) {
if(!$base) $base = BASE_PATH;
+ $tempPath = '';
+ $worked = true;
- if($base) {
- $cachefolder = "silverstripe-cache" . str_replace(array(' ', "/", ":", "\\"), "-", $base);
- } else {
- $cachefolder = "silverstripe-cache";
- }
-
- $ssTmp = BASE_PATH . "/silverstripe-cache";
- if(@file_exists($ssTmp)) {
- return $ssTmp;
+ // first, try finding a silverstripe-cache dir built off the base path
+ $tempPath = $base . '/silverstripe-cache';
+ if(@file_exists($tempPath)) {
+ return $tempPath;
}
- $sysTmp = sys_get_temp_dir();
- $worked = true;
- $ssTmp = "$sysTmp/$cachefolder";
-
- if(!@file_exists($ssTmp)) {
- $worked = @mkdir($ssTmp);
+ // failing the above, try finding a namespaced silverstripe-cache dir in the system temp
+ $cacheFolder = '/silverstripe-cache' . str_replace(array(' ', '/', ':', '\\'), '-', $base);
+ $tempPath = sys_get_temp_dir() . $cacheFolder;
+ if(!@file_exists($tempPath)) {
+ $worked = @mkdir($tempPath);
}
+ // failing to use the system path, attempt to create a local silverstripe-cache dir
if(!$worked) {
- $ssTmp = BASE_PATH . "/silverstripe-cache";
$worked = true;
- if(!@file_exists($ssTmp)) {
- $worked = @mkdir($ssTmp);
+ if(!@file_exists($tempPath)) {
+ $worked = @mkdir($tempPath);
}
}
@@ -346,7 +342,7 @@ function getTempFolder($base = null) {
);
}
- return $ssTmp;
+ return $tempPath;
}
/**

0 comments on commit aa4fa75

Please sign in to comment.