mirror of
https://github.com/torrentpier/torrentpier
synced 2025-08-22 06:13:58 -07:00
Fixed broken file_write() function (#737)
This commit is contained in:
parent
039ec555f2
commit
efe793e699
1 changed files with 7 additions and 9 deletions
18
common.php
18
common.php
|
@ -211,20 +211,18 @@ function bb_log($msg, $file_name, $return_path = false)
|
||||||
function file_write($str, $file, $max_size = LOG_MAX_SIZE, $lock = true, $replace_content = false)
|
function file_write($str, $file, $max_size = LOG_MAX_SIZE, $lock = true, $replace_content = false)
|
||||||
{
|
{
|
||||||
$bytes_written = false;
|
$bytes_written = false;
|
||||||
|
|
||||||
if ($max_size && file_exists($file) && filesize($file) >= $max_size) {
|
|
||||||
$old_name = $file;
|
|
||||||
$ext = '';
|
|
||||||
if (preg_match('#^(.+)(\.[^\\\/]+)$#', $file, $matches)) {
|
|
||||||
[$old_name, $ext] = $matches;
|
|
||||||
}
|
|
||||||
$new_name = $old_name . '_[old]_' . date('Y-m-d_H-i-s_') . getmypid() . $ext;
|
|
||||||
clearstatcache();
|
clearstatcache();
|
||||||
if (!file_exists($new_name)) {
|
|
||||||
|
if (($max_size && file_exists($file) && is_file($file)) && filesize($file) >= $max_size) {
|
||||||
|
$file_parts = pathinfo($file);
|
||||||
|
$new_name = ($file_parts['filename'] . '_[old]_' . date('Y-m-d_H-i-s_') . getmypid() . '.' . $file_parts['extension']);
|
||||||
|
clearstatcache();
|
||||||
|
if (!file_exists($new_name) && !is_file($new_name)) {
|
||||||
rename($file, $new_name);
|
rename($file, $new_name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!file_exists($file) && $dir_created = bb_mkdir(dirname($file))) {
|
clearstatcache();
|
||||||
|
if (!file_exists($file) && !is_file($file) && bb_mkdir(dirname($file))) {
|
||||||
$fp = fopen($file, 'ab+');
|
$fp = fopen($file, 'ab+');
|
||||||
}
|
}
|
||||||
if (isset($fp)) {
|
if (isset($fp)) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue