com web/rmtools: Truncate the db file for reset: include/Branch.php
| From: | Anatol Belski | Date: | Tue, 19 Sep 2017 16:43:35 +0000 |
| Subject: | com web/rmtools: Truncate the db file for reset: include/Branch.php | ||
| Groups: | php.webmaster | ||
| Request: | Send a blank email to php-webmaster+get-26415@lists.php.net to get a copy of this message | ||
Commit: cb41be0fb0a690e01d1f743779bf49e0d1ea38c2
Author: Anatol Belski <ab@php.net> Tue, 19 Sep 2017 18:43:35 +0200
Parents: fd4448d3d3edae90a186c859bebfccbd197d555e
Branches: master
Link: http://git.php.net/?p=web/rmtools.git;a=commitdiff;h=cb41be0fb0a690e01d1f743779bf49e0d1ea38c2
Log:
Truncate the db file for reset
Changed paths:
M include/Branch.php
Diff:
diff --git a/include/Branch.php b/include/Branch.php
index 6cf84aa..4bb86a5 100644
--- a/include/Branch.php
+++ b/include/Branch.php
@@ -44,10 +44,14 @@ class Branch {
/* If both read and write are requested, read and yield data first. The fd
is still open and the exclusive lock is held. Call the function once
more to write. */
- protected function atomicDataRW($read = true, $write = false)
+ protected function atomicDataRW($read = true, $write = false, $truncate = false)
{
if ($write) {
- $open_mode = "cb+";
+ if ($truncate) {
+ $open_mode = "wb+";
+ } else {
+ $open_mode = "cb+";
+ }
$lock_mode = LOCK_EX;
} else {
$open_mode = "rb";
@@ -64,6 +68,7 @@ class Branch {
}
if ($read) {
+ rewind($this->db_fd);
$j = "";
while(!feof($this->db_fd)) {
$j .= fread($this->db_fd, 1024);
@@ -354,10 +359,10 @@ class Branch {
function resetBuildInfo()
{
if ($this->requiredBuildRunsReached()) {
- $this->data = $this->readdata();
+ $this->data = $this->readData();
$this->data->build_num = 0;
$this->data->builds = array();
- $this->writeData();
+ $this->atomicDataRW(false, true, true);
}
}