Skip to content

Commit ddfc29d

Browse files
committed
Attempting to fix #373 again
1 parent 6a667a6 commit ddfc29d

File tree

2 files changed

+15
-16
lines changed

2 files changed

+15
-16
lines changed

src/phpFastCache/CacheManager.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ class CacheManager
5757
*/
5858
protected static $config = [
5959
'itemDetailedDate' => false,// Specify if the item must provide detailed creation/modification dates
60+
'autoTmpFallback' => false,// Automatically attempt to fallback to temporary directory if the cache fails to write on the specified directory
6061
'secureFileManipulation' => false,// Provide a secure file manipulation mechanism, on intensive usage the performance can be affected.
6162
'ignoreSymfonyNotice' => false,// Ignore Symfony notice for Symfony project which do not makes use of PhpFastCache's Symfony Bundle
6263
'defaultTtl' => 900,// Default time-to-live in second

src/phpFastCache/Core/Pool/IO/IOHelperTrait.php

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,11 @@ trait IOHelperTrait
2626
public $tmp = [];
2727

2828
/**
29-
* @param bool $skip_create_path
30-
* @param $config
29+
* @param bool $readonly
3130
* @return string
3231
* @throws phpFastCacheIOException
3332
*/
34-
public function getPath($getBasePath = false)
33+
public function getPath($readonly = false)
3534
{
3635
$tmp_dir = rtrim(ini_get('upload_tmp_dir') ? ini_get('upload_tmp_dir') : sys_get_temp_dir(), '\\/') . DIRECTORY_SEPARATOR . 'phpfastcache';
3736

@@ -51,10 +50,6 @@ public function getPath($getBasePath = false)
5150
$path = $this->config[ 'path' ];
5251
}
5352

54-
if ($getBasePath === true) {
55-
return $path;
56-
}
57-
5853
$securityKey = array_key_exists('securityKey', $this->config) ? $this->config[ 'securityKey' ] : '';
5954
if (!$securityKey || $securityKey === 'auto') {
6055
if (isset($_SERVER[ 'HTTP_HOST' ])) {
@@ -71,28 +66,31 @@ public function getPath($getBasePath = false)
7166
$securityKey = static::cleanFileName($securityKey);
7267

7368
$full_path = rtrim($path, '/') . '/' . $securityKey;
74-
$full_pathx = md5($full_path);
69+
$full_pathx = $full_path;
7570

71+
if ($readonly === true) {
72+
return $full_path;
73+
}
7674

7775
if (!isset($this->tmp[ $full_pathx ]) || (!@file_exists($full_path) || !@is_writable($full_path))) {
7876
if (!@file_exists($full_path)) {
7977
@mkdir($full_path, $this->setChmodAuto(), true);
80-
}
81-
if (!@is_writable($full_path)) {
78+
}else if (!@is_writable($full_path)) {
8279
@chmod($full_path, $this->setChmodAuto());
8380
}
84-
if (!@is_writable($full_path)) {
85-
// switch back to tmp dir again if the path is not writeable
81+
82+
if ($this->config[ 'autoTmpFallback' ] && !@is_writable($full_path)) {
83+
/**
84+
* Switch back to tmp dir
85+
* again if the path is not writable
86+
*/
8687
$full_path = rtrim($tmp_dir, '/') . '/' . $securityKey;
8788
if (!@file_exists($full_path)) {
8889
@mkdir($full_path, $this->setChmodAuto(), true);
8990
}
90-
if (!@is_writable($full_path)) {
91-
@chmod($full_path, $this->setChmodAuto());
92-
}
9391
}
9492
if (!@file_exists($full_path) || !@is_writable($full_path)) {
95-
throw new phpFastCacheIOException('PLEASE CREATE OR CHMOD ' . $full_path . ' - 0777 OR ANY WRITABLE PERMISSION!', 92);
93+
throw new phpFastCacheIOException('PLEASE CREATE OR CHMOD ' . $full_path . ' - 0777 OR ANY WRITABLE PERMISSION!');
9694
}
9795

9896
$this->tmp[ $full_pathx ] = true;

0 commit comments

Comments
 (0)