mirror of
https://gitee.com/ulthon/ulthon_admin.git
synced 2026-07-09 03:22:51 +08:00
优化判断机制
This commit is contained in:
@@ -132,6 +132,55 @@ class PathToolsBase
|
|||||||
|
|
||||||
$result = true;
|
$result = true;
|
||||||
|
|
||||||
|
// 如果前面的方法认为文件变化,那么以文本变化的方式识别是否变化,并给出变化的内容
|
||||||
|
$text_mime_type = [];
|
||||||
|
$text_mime_type[] = 'text/html';
|
||||||
|
$text_mime_type[] = 'text/plain';
|
||||||
|
$text_mime_type[] = 'text/css';
|
||||||
|
$text_mime_type[] = 'image/svg+xml';
|
||||||
|
$text_mime_type[] = 'text/x-php';
|
||||||
|
$text_mime_type[] = 'application/json';
|
||||||
|
$text_mime_type[] = 'application/x-wine-extension-ini';
|
||||||
|
|
||||||
|
if (in_array(mime_content_type($a), $text_mime_type) && in_array(mime_content_type($b), $text_mime_type)) {
|
||||||
|
$a_content = file_get_contents($a);
|
||||||
|
$b_content = file_get_contents($b);
|
||||||
|
|
||||||
|
$a_content = str_replace("\r\n", "\n", $a_content);
|
||||||
|
$b_content = str_replace("\r\n", "\n", $b_content);
|
||||||
|
|
||||||
|
// 将空格和制表符转换为一个空格
|
||||||
|
$a_content = preg_replace('/[ \t]+/', ' ', $a_content);
|
||||||
|
$b_content = preg_replace('/[ \t]+/', ' ', $b_content);
|
||||||
|
|
||||||
|
$a_content_arr = mb_str_split($a_content);
|
||||||
|
$b_content_arr = mb_str_split($b_content);
|
||||||
|
|
||||||
|
$a_content_length = count($a_content_arr);
|
||||||
|
|
||||||
|
$diff_content = [];
|
||||||
|
for ($i = 0; $i < $a_content_length; $i++) {
|
||||||
|
$diff_char = [];
|
||||||
|
$diff_char['path_a'] = $a;
|
||||||
|
$diff_char['path_b'] = $b;
|
||||||
|
$diff_char['index'] = $i;
|
||||||
|
if (isset($b_content_arr[$i])) {
|
||||||
|
if ($a_content_arr[$i] !== $b_content_arr[$i]) {
|
||||||
|
$diff_char['a'] = $a_content_arr[$i];
|
||||||
|
$diff_char['b'] = $b_content_arr[$i];
|
||||||
|
$diff_content[] = $diff_char;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$diff_char['a'] = $a_content_arr[$i];
|
||||||
|
$diff_char['b'] = '';
|
||||||
|
$diff_content[] = $diff_char;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (count($diff_content) > 0) {
|
||||||
|
$result = false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
// Check if filesize is different
|
// Check if filesize is different
|
||||||
if (filesize($a) !== filesize($b)) {
|
if (filesize($a) !== filesize($b)) {
|
||||||
$result = false;
|
$result = false;
|
||||||
@@ -152,36 +201,6 @@ class PathToolsBase
|
|||||||
fclose($ah);
|
fclose($ah);
|
||||||
fclose($bh);
|
fclose($bh);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$result) {
|
|
||||||
// 如果前面的方法认为文件变化,那么以文本变化的方式识别是否变化,并给出变化的内容
|
|
||||||
$text_mime_type = [];
|
|
||||||
$text_mime_type[] = 'text/html';
|
|
||||||
$text_mime_type[] = 'text/plain';
|
|
||||||
$text_mime_type[] = 'text/css';
|
|
||||||
$text_mime_type[] = 'image/svg+xml';
|
|
||||||
$text_mime_type[] = 'text/x-php';
|
|
||||||
$text_mime_type[] = 'application/json';
|
|
||||||
$text_mime_type[] = 'application/x-wine-extension-ini';
|
|
||||||
|
|
||||||
if (in_array(mime_content_type($a), $text_mime_type) && in_array(mime_content_type($b), $text_mime_type)) {
|
|
||||||
$a_content = file_get_contents($a);
|
|
||||||
$b_content = file_get_contents($b);
|
|
||||||
|
|
||||||
$a_content_length = strlen($a_content);
|
|
||||||
$b_content_length = strlen($b_content);
|
|
||||||
|
|
||||||
if ($a_content_length !== $b_content_length) {
|
|
||||||
$result = false;
|
|
||||||
} else {
|
|
||||||
for ($i = 0; $i < $a_content_length; $i++) {
|
|
||||||
if ($a_content[$i] !== $b_content[$i]) {
|
|
||||||
$result = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
|
|||||||
Reference in New Issue
Block a user