diff --git a/debian/changelog b/debian/changelog index 73f16a5d878530b572017cca60fcbca24d550bc3..197dd5a402d57dfd542066553d06447cd205ab04 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 4263925f9e8f5261d068d8fbee96ad0c16cdb20a..127b0682dd5532bcb3a332a026c59d0dead896b0 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)