Skip to content

Commit

Permalink
Append additional (error) message only if error_get_last() returns …
Browse files Browse the repository at this point in the history
…non-null value #20294
  • Loading branch information
xcopy committed Dec 8, 2024
1 parent 0b3370e commit b3c23da
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
15 changes: 7 additions & 8 deletions framework/caching/FileCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,7 @@ protected function setValue($key, $value, $duration)
}

$message = "Unable to write cache file '{$cacheFile}'";

if ($error = error_get_last()) {
$message .= ": {$error['message']}";
}
($error = error_get_last()) and $message .= ": {$error['message']}";

Check warning on line 162 in framework/caching/FileCache.php

View check run for this annotation

Codecov / codecov/patch

framework/caching/FileCache.php#L161-L162

Added lines #L161 - L162 were not covered by tests

Yii::warning($message, __METHOD__);

Check warning on line 164 in framework/caching/FileCache.php

View check run for this annotation

Codecov / codecov/patch

framework/caching/FileCache.php#L164

Added line #L164 was not covered by tests

Expand Down Expand Up @@ -271,20 +268,22 @@ protected function gcRecursive($path, $expiredOnly)
continue;
}
$fullPath = $path . DIRECTORY_SEPARATOR . $file;
$message = null;
if (is_dir($fullPath)) {
$this->gcRecursive($fullPath, $expiredOnly);
if (!$expiredOnly) {
if (!@rmdir($fullPath)) {
$error = error_get_last();
Yii::warning("Unable to remove directory '{$fullPath}': {$error['message']}", __METHOD__);
$message = "Unable to remove directory '$fullPath'";

Check warning on line 276 in framework/caching/FileCache.php

View check run for this annotation

Codecov / codecov/patch

framework/caching/FileCache.php#L276

Added line #L276 was not covered by tests
($error = error_get_last()) and $message .= ": {$error['message']}";
}
}
} elseif (!$expiredOnly || $expiredOnly && @filemtime($fullPath) < time()) {
if (!@unlink($fullPath)) {
$error = error_get_last();
Yii::warning("Unable to remove file '{$fullPath}': {$error['message']}", __METHOD__);
$message = "Unable to remove file '$fullPath'";
($error = error_get_last()) and $message .= ": {$error['message']}";

Check warning on line 283 in framework/caching/FileCache.php

View check run for this annotation

Codecov / codecov/patch

framework/caching/FileCache.php#L282-L283

Added lines #L282 - L283 were not covered by tests
}
}
$message and Yii::warning($message, __METHOD__);
}
closedir($handle);
}
Expand Down
5 changes: 3 additions & 2 deletions framework/log/FileTarget.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,9 @@ public function export()
}
$writeResult = @fwrite($fp, $text);
if ($writeResult === false) {
$error = error_get_last();
throw new LogRuntimeException("Unable to export log through file ({$this->logFile})!: {$error['message']}");
$message = "Unable to export log through file ($this->logFile)!";
($error = error_get_last()) and $message .= ": {$error['message']}";
throw new LogRuntimeException($message);

Check warning on line 136 in framework/log/FileTarget.php

View check run for this annotation

Codecov / codecov/patch

framework/log/FileTarget.php#L134-L136

Added lines #L134 - L136 were not covered by tests
}
$textSize = strlen($text);
if ($writeResult < $textSize) {
Expand Down

0 comments on commit b3c23da

Please sign in to comment.