From 09164e7e2a32accd56ade5e1552fe839c55ebcb8 Mon Sep 17 00:00:00 2001 From: Sam Minnee Date: Tue, 23 May 2017 10:06:30 +1200 Subject: [PATCH] FIX: Better error checking for non-writable temp paths Fixes https://github.com/silverstripe/silverstripe-framework/issues/1666 --- src/Core/TempPath.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/Core/TempPath.php b/src/Core/TempPath.php index 154d90993..6cb0c1800 100644 --- a/src/Core/TempPath.php +++ b/src/Core/TempPath.php @@ -60,8 +60,6 @@ function getTempParentFolder($base = null) $base = BASE_PATH; } - $worked = true; - // first, try finding a silverstripe-cache dir built off the base path $tempPath = $base . DIRECTORY_SEPARATOR . 'silverstripe-cache'; if (@file_exists($tempPath)) { @@ -77,7 +75,7 @@ function getTempParentFolder($base = null) str_replace(array(' ', '/', ':', '\\'), '-', $base); if (!@file_exists($tempPath)) { $oldUMask = umask(0); - $worked = @mkdir($tempPath, 0777); + @mkdir($tempPath, 0777); umask($oldUMask); // if the folder already exists, correct perms @@ -87,15 +85,18 @@ function getTempParentFolder($base = null) } } + $worked = @file_exists($tempPath) && @is_writable($tempPath); + // failing to use the system path, attempt to create a local silverstripe-cache dir if (!$worked) { - $worked = true; $tempPath = $base . DIRECTORY_SEPARATOR . 'silverstripe-cache'; if (!@file_exists($tempPath)) { $oldUMask = umask(0); - $worked = @mkdir($tempPath, 0777); + @mkdir($tempPath, 0777); umask($oldUMask); } + + $worked = @file_exists($tempPath) && @is_writable($tempPath); } if (!$worked) {