Skip to content

Commit 389dec2

Browse files
committed
Bug-fix.
Changelog excerpt: - Log truncation not being calculated properly; Fixed.
1 parent e886e66 commit 389dec2

File tree

3 files changed

+14
-18
lines changed

3 files changed

+14
-18
lines changed

Changelog.md

+2
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,5 @@ __*Why "v3.0.0" instead of "v1.0.0?"*__ Prior to phpMussel v3, the "phpMussel Co
4545
[2021.03.11; Maikuolan]: Added some missing return type declarations.
4646

4747
[2021.04.19; Bug-fix; Maikuolan]: BuildPath could potentially trigger warnings when open_basedir is defined, causing logging, among various other internal file operations, to fail (related to PHP bug 69240); Fixed.
48+
49+
[2021.05.01; Bug-fix; Maikuolan]: Log truncation not being calculated properly; Fixed.

src/Loader.php

+7-7
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* License: GNU/GPLv2
99
* @see LICENSE.txt
1010
*
11-
* This file: The loader (last modified: 2021.04.19).
11+
* This file: The loader (last modified: 2021.05.01).
1212
*/
1313

1414
namespace phpMussel\Core;
@@ -371,17 +371,14 @@ public function __construct(
371371
return false;
372372
}
373373

374-
if (!file_exists($File) || !filesize($File) || (
375-
$this->Configuration['core']['truncate'] > 0 &&
376-
filesize($File) >= $this->readBytes($this->Configuration['core']['truncate'])
377-
)) {
374+
$Truncate = $this->readBytes($this->Configuration['core']['truncate']);
375+
if (!file_exists($File) || !filesize($File) || ($Truncate && filesize($File) >= $Truncate)) {
378376
$WriteMode = 'wb';
379377
$Data = $this->L10N->getString('error_log_header') . "\n=====\n" . $this->InstanceCache['PendingErrorLogData'];
380378
} else {
381379
$WriteMode = 'ab';
382380
$Data = $this->InstanceCache['PendingErrorLogData'];
383381
}
384-
385382
$Handle = fopen($File, $WriteMode);
386383
if (is_resource($Handle)) {
387384
fwrite($Handle, $Data);
@@ -475,7 +472,10 @@ public function readBytes(string $In, int $Mode = 0)
475472
return $Unit === 'B' || $Unit === 'o' ? $In . 'B' : $In . $Unit . 'B';
476473
}
477474
$Multiply = ['K' => 1024, 'M' => 1048576, 'G' => 1073741824, 'T' => 1099511627776];
478-
return (int)floor($In * (isset($Multiply[$Unit]) ? $Multiply[$Unit] : 1));
475+
if (isset($Multiply[$Unit])) {
476+
$In *= $Multiply[$Unit];
477+
}
478+
return (int)floor($In);
479479
}
480480

481481
/**

src/Scanner.php

+5-11
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* License: GNU/GPLv2
99
* @see LICENSE.txt
1010
*
11-
* This file: The scanner (last modified: 2021.03.20).
11+
* This file: The scanner (last modified: 2021.05.01).
1212
*/
1313

1414
namespace phpMussel\Core;
@@ -105,11 +105,8 @@ public function __construct(\phpMussel\Core\Loader &$Loader)
105105
'ScanErrors' => $this->Loader->InstanceCache['ScanErrors'] ?? 1,
106106
'Detections' => $Detections
107107
]) . "\n";
108-
$WriteMode = (!file_exists($File) || (
109-
$this->Loader->Configuration['core']['truncate'] > 0 &&
110-
filesize($File) >= $this->Loader->readBytes($this->Loader->Configuration['core']['truncate'])
111-
)) ? 'wb' : 'ab';
112-
108+
$Truncate = $this->Loader->readBytes($this->Loader->Configuration['core']['truncate']);
109+
$WriteMode = (!file_exists($File) || ($Truncate > 0 && filesize($File) >= $Truncate)) ? 'wb' : 'ab';
113110
$Stream = fopen($File, $WriteMode);
114111
fwrite($Stream, $Data);
115112
fclose($Stream);
@@ -145,12 +142,9 @@ public function __construct(\phpMussel\Core\Loader &$Loader)
145142
$Results = \phpMussel\Core\Loader::SAFETY . "\n" . $Results;
146143
$WriteMode = 'wb';
147144
} else {
148-
$WriteMode = (
149-
$this->Loader->Configuration['core']['truncate'] > 0 &&
150-
filesize($File) >= $this->Loader->readBytes($this->Loader->Configuration['core']['truncate'])
151-
) ? 'wb' : 'ab';
145+
$Truncate = $this->Loader->readBytes($this->Loader->Configuration['core']['truncate']);
146+
$WriteMode = ($Truncate > 0 && filesize($File) >= $Truncate) ? 'wb' : 'ab';
152147
}
153-
154148
$Handle = fopen($File, 'ab');
155149
fwrite($Handle, $Results);
156150
fclose($Handle);

0 commit comments

Comments
 (0)