From 9db07ffbc6260db43a978e7f738d828898191cf0 Mon Sep 17 00:00:00 2001 From: ruizhe Date: Thu, 19 Oct 2023 14:13:40 +0800 Subject: [PATCH] =?UTF-8?q?chore:=E6=9B=B4=E6=96=B0=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E5=AE=B6=E7=9B=AE=E5=BD=95=E7=9A=84=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- debian/changelog | 6 ++++++ getcontent.cpp | 17 ++++++++--------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/debian/changelog b/debian/changelog index 73f16a5..197dd5a 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +nfs-logtools (1.0.0-7) unstable; urgency=medium + + * fix: update get home path method. + + -- ruizhe Thu, 19 Oct 2023 14:11:13 +0800 + nfs-logtools (1.0.0-6) unstable; urgency=medium * fix: cannot reopen when program crashes. diff --git a/getcontent.cpp b/getcontent.cpp index 4263925..127b068 100644 --- a/getcontent.cpp +++ b/getcontent.cpp @@ -9,7 +9,7 @@ QString GetContent::getHomePath() QProcess *execCmd = new QProcess(); QStringList params; QStringList getUserName; - QStringList curHome; + QString curHome; QString curUserByWho = ""; QString curUserByLast = ""; QString curUser = ""; @@ -44,7 +44,7 @@ QString GetContent::getHomePath() tmpLine.clear(); } } - + //取第一个非root的用户 int i = 0; do { if (contentList[i].contains("root", Qt::CaseInsensitive)) { @@ -61,15 +61,14 @@ QString GetContent::getHomePath() else { return "/root"; } - - execCmd->start("bash", QStringList() << "-c" << "cat /etc/passwd | grep " + curUser); + + curUser = curUser + ':'; + execCmd->start("bash", QStringList() << "-c" << "cat /etc/passwd | grep ^" + curUser + " | cut -d ':' -f 6"); execCmd->waitForFinished(); curUsrPawdInfo = execCmd->readAllStandardOutput(); - execCmd->close(); - - curHome = curUsrPawdInfo.split(':'); - - return curHome[5]; + curHome = curUsrPawdInfo.replace(QRegExp("\n"), ""); + + return curHome; } bool GetContent::checkLogPathExists(QString &logPath) -- Gitee