Skip to content

Commit 77485e3

Browse files
author
arcfieldOSS
committed
switch to "copy into place" for file writing
make file writing return a failure state if any portion of writing fails add checks to remove "Warning:" messages from phpfastcache for uninitialized array access.
1 parent 74ceb4c commit 77485e3

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

phpfastcache/3.0.0/drivers/files.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ function driver_set($keyword, $value = "", $time = 300, $option = array() ) {
8787
}
8888
}
8989

90+
$written = true;
9091
/*
9192
* write to intent file to prevent race during read; race during write is ok
9293
* because first-to-lock wins and the file will exist before the writer attempts
@@ -95,20 +96,24 @@ function driver_set($keyword, $value = "", $time = 300, $option = array() ) {
9596
if($toWrite == true && !@file_exists($tmp_path && !@file_exists($file_path))) {
9697
try {
9798
$f = @fopen($tmp_path, "c");
99+
if ($f) {
98100
if (flock($f,LOCK_EX| LOCK_NB)) {
99-
fwrite($f, $data);
100-
fflush($f);
101-
flock($f,LOCK_UN);
101+
$written = ($written && fwrite($f, $data));
102+
$written = ($written && fflush($f));
103+
$written = ($written && flock($f, LOCK_UN));
102104
} else {
103105
//arguably the file is being written to so the job is done
106+
$written = false;
107+
}
108+
$written = ($written && @fclose($f));
109+
$written = ($written && @rename($tmp_path,$file_path));
104110
}
105-
fclose($f);
106-
@rename($tmp_path,$file_path);
107111
} catch (Exception $e) {
108112
// miss cache
109-
return false;
113+
$written = false;
110114
}
111115
}
116+
return $written;
112117
}
113118

114119
function driver_get($keyword, $option = array()) {

phpfastcache/3.0.0/phpfastcache.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ public static function getPath($skip_create_path = false, $config) {
159159
$path = $config['path'];
160160
}
161161

162-
$securityKey = $config['securityKey'];
162+
$securityKey = array_key_exists('securityKey',$config) ? $config['securityKey'] : "";
163163
if($securityKey == "" || $securityKey == "auto") {
164164
$securityKey = self::$config['securityKey'];
165165
if($securityKey == "auto" || $securityKey == "") {
@@ -193,7 +193,7 @@ public static function getPath($skip_create_path = false, $config) {
193193

194194

195195
self::$tmp[$full_pathx] = true;
196-
self::htaccessGen($full_path, $config['htaccess']);
196+
self::htaccessGen($full_path, array_key_exists('htaccess',$config) ? $config['htaccess'] : false);
197197
}
198198

199199
return realpath($full_path);

0 commit comments

Comments
 (0)