• R/O
  • HTTP
  • SSH
  • HTTPS

pukiwiki: Commit


Commit MetaInfo

Revisionef13260aa62b4b4d6d7da5f9c85a568eee44aa24 (tree)
Time2016-12-03 06:20:49
Authorumorigu <umorigu@gmai...>
Commiterumorigu

Log Message

BugTrack/2401 Locked file_get_contents/file_put_contents on bugtrack

It needs locking for a bugtrack_list cache file.

* file_put_contents lock bug was fixed on PHP 5.2.6 .

  • bugtrack_list is for PHP5.4+. So we can use it.

* file_get_content has no lock mechanism. I added pkwk_file_get_contents.

Change Summary

Incremental Difference

--- a/lib/file.php
+++ b/lib/file.php
@@ -841,3 +841,19 @@ function pkwk_touch_file($filename, $time = FALSE, $atime = FALSE)
841841 htmlsc(basename($filename)));
842842 }
843843 }
844+
845+/**
846+ * Lock-enabled file_get_contents
847+ *
848+ * Require: PHP5+
849+ */
850+function pkwk_file_get_contents($filename) {
851+ if (! file_exists($filename)) {
852+ return false;
853+ }
854+ $fp = fopen($filename, 'rb');
855+ flock($fp, LOCK_SH);
856+ $file = file_get_contents($filename);
857+ flock($fp, LOCK_UN);
858+ return $file;
859+}
--- a/plugin/bugtrack.inc.php
+++ b/plugin/bugtrack.inc.php
@@ -307,7 +307,7 @@ function plugin_bugtrack_list_convert()
307307 // Cache management
308308 $data_updated = true;
309309 $cache_filepath = CACHE_DIR . encode($page) . '.bugtrack';
310- $json_cached = file_get_contents($cache_filepath);
310+ $json_cached = pkwk_file_get_contents($cache_filepath);
311311 if ($json_cached) {
312312 $wrapdata = json_decode($json_cached);
313313 if (is_object($wrapdata)) {
@@ -394,7 +394,7 @@ EOD;
394394 }
395395 $json = array('refreshed_at'=>$refreshed_at, 'pages'=>$data, 'version'=>$cache_format_version);
396396 $cache_body = json_encode($json, JSON_UNESCAPED_UNICODE + JSON_UNESCAPED_SLASHES);
397- file_put_contents($cache_filepath, $cache_body);
397+ file_put_contents($cache_filepath, $cache_body, LOCK_EX);
398398 }
399399 }
400400 $table = array();
Show on old repository browser