Merge pull request #517 from torrentpier/fixed-broken-file_write

Fixed broken file_write() function
This commit is contained in:
Roman Kelesidis 2023-01-23 20:26:39 +07:00 committed by GitHub
commit 65bdac8887
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -248,19 +248,19 @@ function file_write($str, $file, $max_size = LOG_MAX_SIZE, $lock = true, $replac
rename($file, $new_name); rename($file, $new_name);
} }
} }
if (file_exists($file) && $dir_created = bb_mkdir(dirname($file))) {
$fp = fopen($file, 'ab+'); if (bb_mkdir(dirname($file))) {
} if ($fp = fopen($file, 'ab+')) {
if (isset($fp)) { if ($lock) {
if ($lock) { flock($fp, LOCK_EX);
flock($fp, LOCK_EX); }
if ($replace_content) {
ftruncate($fp, 0);
fseek($fp, 0, SEEK_SET);
}
$bytes_written = fwrite($fp, $str);
fclose($fp);
} }
if ($replace_content) {
ftruncate($fp, 0);
fseek($fp, 0, SEEK_SET);
}
$bytes_written = fwrite($fp, $str);
fclose($fp);
} }
return $bytes_written; return $bytes_written;