From 61e8efbd756cad6d674260b4579be73eba123f57 Mon Sep 17 00:00:00 2001 From: DuanRay Date: Wed, 18 Oct 2023 15:38:47 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E4=BF=AE=E5=A4=8D=E6=97=A5=E5=BF=97?= =?UTF-8?q?=E5=88=86=E6=9E=90=E5=B7=A5=E5=85=B7=E7=AD=9B=E9=80=89=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=E5=BC=82=E5=B8=B8=EF=BC=8C=E7=AD=9B=E9=80=89=E7=BB=93?= =?UTF-8?q?=E6=9E=9C=E5=92=8C=E7=AD=9B=E9=80=89=E6=9D=A1=E4=BB=B6=E4=B8=8D?= =?UTF-8?q?=E5=8C=B9=E9=85=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 0007-fix-filter-find-error.patch | 259 +++++++++++++++++++++++++++++++ nfs-logtools.spec | 6 +- 2 files changed, 264 insertions(+), 1 deletion(-) create mode 100644 0007-fix-filter-find-error.patch diff --git a/0007-fix-filter-find-error.patch b/0007-fix-filter-find-error.patch new file mode 100644 index 0000000..65ac09a --- /dev/null +++ b/0007-fix-filter-find-error.patch @@ -0,0 +1,259 @@ +diff --git a/nfs-logtools-1.0.0/logtools.cpp b/nfs-logtools-1.0.0/logtools.cpp +index 800ebd8..c8ff735 100644 +--- a/nfs-logtools-1.0.0/logtools.cpp ++++ b/nfs-logtools-1.0.0/logtools.cpp +@@ -848,7 +848,7 @@ void Logtools::logtoolsFilterNearlyAllGetData() + void Logtools::logtoolsFilterNearlyTodayGetData() + { + QDateTime currentDateTime = QDateTime::currentDateTime(); +- QString currentDate = currentDateTime.toString("M-dd"); ++ QString currentDate = currentDateTime.toString("MM-dd"); + QString dataTemp; + QList > temp; + temp.clear(); +@@ -869,7 +869,7 @@ void Logtools::logtoolsFilterNearlyTodayGetData() + + void Logtools::logtoolsFilterNearlyThreeDayGetData() + { +- #define DATATIMESIZE 4 ++ #define DATATIMESIZE 5 + QDateTime currentDateTime = QDateTime::currentDateTime(); + QString currentYear = currentDateTime.toString("yyyy"); + QString dataTemp; +@@ -884,7 +884,7 @@ void Logtools::logtoolsFilterNearlyThreeDayGetData() + if (dataTemp.size() == DATATIMESIZE) { //区分带年份和不带年份 + dataTemp = currentYear + "-" + dataTemp; + } +- dataTempTime = QDateTime::fromString(dataTemp, "yyyy-M-dd"); ++ dataTempTime = QDateTime::fromString(dataTemp, "yyyy-MM-dd"); + days = currentDateTime.daysTo(dataTempTime); + if (days < NEARLYTHREEDAY) { + break; +@@ -897,7 +897,7 @@ void Logtools::logtoolsFilterNearlyThreeDayGetData() + + void Logtools::logtoolsFilterNearlyWeekGetData() + { +- #define DATATIMESIZE 4 ++ #define DATATIMESIZE 5 + QDateTime currentDateTime = QDateTime::currentDateTime(); + QString currentYear = currentDateTime.toString("yyyy"); + QString dataTemp; +@@ -912,7 +912,7 @@ void Logtools::logtoolsFilterNearlyWeekGetData() + if (dataTemp.size() == DATATIMESIZE) { //区分带年份和不带年份 + dataTemp = currentYear + "-" + dataTemp; + } +- dataTempTime = QDateTime::fromString(dataTemp, "yyyy-M-dd"); ++ dataTempTime = QDateTime::fromString(dataTemp, "yyyy-MM-dd"); + days = currentDateTime.daysTo(dataTempTime); + if (days < NEARLYWEEK) { + break; +@@ -925,7 +925,7 @@ void Logtools::logtoolsFilterNearlyWeekGetData() + + void Logtools::logtoolsFilterNearlyMonthGetData() + { +- #define DATATIMESIZE 4 ++ #define DATATIMESIZE 5 + QDateTime currentDateTime = QDateTime::currentDateTime(); + QString currentYear = currentDateTime.toString("yyyy"); + QString dataTemp; +@@ -940,7 +940,7 @@ void Logtools::logtoolsFilterNearlyMonthGetData() + if (dataTemp.size() == DATATIMESIZE) { //区分带年份和不带年份 + dataTemp = currentYear + "-" + dataTemp; + } +- dataTempTime = QDateTime::fromString(dataTemp, "yyyy-M-dd"); ++ dataTempTime = QDateTime::fromString(dataTemp, "yyyy-MM-dd"); + days = currentDateTime.daysTo(dataTempTime); + if (days < NEARLYMONTH) { + break; +@@ -953,7 +953,7 @@ void Logtools::logtoolsFilterNearlyMonthGetData() + + void Logtools::logtoolsFilterNearlyThreeMonthGetData() + { +- #define DATATIMESIZE 4 ++ #define DATATIMESIZE 5 + QDateTime currentDateTime = QDateTime::currentDateTime(); + QString currentYear = currentDateTime.toString("yyyy"); + QString dataTemp; +@@ -968,7 +968,7 @@ void Logtools::logtoolsFilterNearlyThreeMonthGetData() + if (dataTemp.size() == DATATIMESIZE) { //区分带年份和不带年份 + dataTemp = currentYear + "-" + dataTemp; + } +- dataTempTime = QDateTime::fromString(dataTemp, "yyyy-M-dd"); ++ dataTempTime = QDateTime::fromString(dataTemp, "yyyy-MM-dd"); + days = currentDateTime.daysTo(dataTempTime); + if (days < NEARLYTHREEMONTH) { + break; +diff --git a/nfs-logtools-1.0.0/parserlog.cpp b/nfs-logtools-1.0.0/parserlog.cpp +index 6b22cd7..5a2378b 100644 +--- a/nfs-logtools-1.0.0/parserlog.cpp ++++ b/nfs-logtools-1.0.0/parserlog.cpp +@@ -29,6 +29,26 @@ void ParserLog::formatString(QString &str) + str.replace(QRegExp("[\\s]+"), " "); + } + ++void ParserLog::formatDate(QString &date) ++{ ++ QDateTime tempDate; ++ date = date.trimmed(); ++ ++ switch (date.count('-')) { ++ case 1: ++ tempDate = QDateTime::fromString(date, "M-d"); ++ date = tempDate.toString("MM-dd"); ++ break; ++ case 2: ++ tempDate = QDateTime::fromString(date, "yyyy-M-d"); ++ date = tempDate.toString("yyyy-MM-dd"); ++ break; ++ default: ++ qDebug() << "Not formatted."; ++ break; ++ } ++} ++ + void ParserLog::reverseQList(QList > &str) + { + QList > temp; +@@ -71,8 +91,8 @@ void ParserLog::parserSwitch(QList > &logList) + + //获取week的位置 + weekPosition = lineContent.indexOf(QRegExp(weekMatch)); +- const QString date = lineContent[weekPosition+4] + "-" + month[lineContent[weekPosition+1]] + "-" + lineContent[weekPosition+2]; +- ++ QString date = lineContent[weekPosition+4] + "-" + month[lineContent[weekPosition+1]] + "-" + lineContent[weekPosition+2]; ++ formatDate(date); + map.insert("日期", date); + map.insert("时间", lineContent[weekPosition+3]); + map.insert("动作", lineContent[0]); +@@ -156,6 +176,7 @@ void ParserLog::parserSysInfo(QList > &logList) + formatString(leftString); //去除多余的空格 + lineContent = leftString.split(" "); + date = month[lineContent[0]] + "-" + lineContent[1]; ++ formatDate(date); + map.insert("日期", date); + time = lineContent[2]; + map.insert("时间", time); +@@ -227,6 +248,7 @@ void ParserLog::parserPackage(QList > &logList) + status == "startup" || status == "trigproc") { + continue; + } ++ formatDate(lineContent[0]); + map.insert("日期", lineContent[0]); + map.insert("时间", lineContent[1]); + map.insert("状态", lineContent[2]); +@@ -282,6 +304,7 @@ void ParserLog::parserKernel(QList > &logList) + formatString(temp); //去除多余的空格 + lineContent = temp.split(" "); + date = month[lineContent[0]] + "-" + lineContent[1]; ++ formatDate(date); + map.insert("日期", date); + time = lineContent[2]; + map.insert("时间", time); +@@ -304,6 +327,7 @@ void ParserLog::parserSoftwareUpdate(QList > &logList) + description = ""; + lineContent = it->split(" "); + ++ formatDate(lineContent[1]); + map.insert("日期", lineContent[1]); + //清除时间中最后一个: + lineContent[2].replace(QRegExp(":$"), ""); +@@ -341,6 +365,7 @@ void ParserLog::parserPrint(QList > &logList) + timeString = tempString.section(":", 1, 3);//取出00:09:09 +0800 + date = dateString.split("/");//以/分割11/Aug/2022 + dateString = date[2] + "-" + month[date[1]] + "-" + date[0]; ++ formatDate(dateString); + map.insert("日期", dateString); + time = timeString.split(" ");//以" "分割00:09:09 +0800 + map.insert("时间", time[0]); +@@ -486,6 +511,7 @@ void ParserLog::parserApplication(QList > &logList) + formatString(leftString); //去除多余的空格 + lineContent = leftString.split(" "); + date = month[lineContent[0]] + "-" + lineContent[1]; ++ formatDate(date); + map.insert("日期", date); + time = lineContent[2]; + map.insert("时间", time); +@@ -589,6 +615,7 @@ void ParserLog::parserDebug(QList > &logList) + formatString(leftString); //去除多余的空格 + lineContent = leftString.split(" "); + date = month[lineContent[0]] + "-" + lineContent[1]; ++ formatDate(date); + map.insert("日期", date); + time = lineContent[2]; + map.insert("时间", time); +@@ -642,6 +669,7 @@ void ParserLog::parserInfo(QList > &logList) + formatString(leftString); //去除多余的空格 + lineContent = leftString.split(" "); + date = month[lineContent[0]] + "-" + lineContent[1]; ++ formatDate(date); + map.insert("日期", date); + time = lineContent[2]; + map.insert("时间", time); +@@ -695,6 +723,7 @@ void ParserLog::parserNotice(QList > &logList) + formatString(leftString); //去除多余的空格 + lineContent = leftString.split(" "); + date = month[lineContent[0]] + "-" + lineContent[1]; ++ formatDate(date); + map.insert("日期", date); + time = lineContent[2]; + map.insert("时间", time); +@@ -748,6 +777,7 @@ void ParserLog::parserWarning(QList > &logList) + formatString(leftString); //去除多余的空格 + lineContent = leftString.split(" "); + date = month[lineContent[0]] + "-" + lineContent[1]; ++ formatDate(date); + map.insert("日期", date); + time = lineContent[2]; + map.insert("时间", time); +@@ -801,6 +831,7 @@ void ParserLog::parserError(QList > &logList) + formatString(leftString); //去除多余的空格 + lineContent = leftString.split(" "); + date = month[lineContent[0]] + "-" + lineContent[1]; ++ formatDate(date); + map.insert("日期", date); + time = lineContent[2]; + map.insert("时间", time); +@@ -854,6 +885,7 @@ void ParserLog::parserCritical(QList > &logList) + formatString(leftString); //去除多余的空格 + lineContent = leftString.split(" "); + date = month[lineContent[0]] + "-" + lineContent[1]; ++ formatDate(date); + map.insert("日期", date); + time = lineContent[2]; + map.insert("时间", time); +@@ -907,6 +939,7 @@ void ParserLog::parserAlert(QList > &logList) + formatString(leftString); //去除多余的空格 + lineContent = leftString.split(" "); + date = month[lineContent[0]] + "-" + lineContent[1]; ++ formatDate(date); + map.insert("日期", date); + time = lineContent[2]; + map.insert("时间", time); +@@ -960,6 +993,7 @@ void ParserLog::parserEmerg(QList > &logList) + formatString(leftString); //去除多余的空格 + lineContent = leftString.split(" "); + date = month[lineContent[0]] + "-" + lineContent[1]; ++ formatDate(date); + map.insert("日期", date); + time = lineContent[2]; + map.insert("时间", time); +diff --git a/nfs-logtools-1.0.0/parserlog.h b/nfs-logtools-1.0.0/parserlog.h +index a573db4..ab60af9 100644 +--- a/nfs-logtools-1.0.0/parserlog.h ++++ b/nfs-logtools-1.0.0/parserlog.h +@@ -10,6 +10,7 @@ + #include + #include + #include ++#include + #include "getcontent.h" + + #define HOSTINDEX 3 +@@ -21,6 +22,7 @@ class ParserLog : public QObject + public: + ParserLog(); + static void formatString(QString &);//去除多余的空格 ++ static void formatDate(QString &); //格式化日期 + static void reverseQList(QList > &); + + static void parserSwitch(QList > &); //wtmp diff --git a/nfs-logtools.spec b/nfs-logtools.spec index cb02c94..d531221 100644 --- a/nfs-logtools.spec +++ b/nfs-logtools.spec @@ -3,7 +3,7 @@ Name: nfs-logtools Version: 1.0.0 -Release: 6%{?dist} +Release: 7%{?dist} Summary: A log tools of Nfs. License: GPLv2+ Source0: %{name}-%{version}.tar.gz @@ -13,6 +13,7 @@ Patch2: 0003-auto-scaling-and-fix-error.patch Patch3: 0004-after-export-all-log-program-abort.patch Patch4: 0005-fix-cannot-reopen-when-program-crashes.patch Patch5: 0006-fix-get-home-path-method.patch +Patch6: 0007-fix-filter-find-error.patch BuildRequires: qt5-qttools-devel qt5-qtbase-devel glibc-devel Requires: coreutils @@ -46,6 +47,9 @@ make %{?_smp_mflags} /usr/sbin/nfs-logtools %changelog +* Wed Oct 18 2023 ruizhe - 1.0.0-7 +- Fix find filter error + * Wed Oct 18 2023 ruizhe - 1.0.0-6 - Fix get home path method -- Gitee