Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Resolve the issue of adding sudo not being able to export logs #266

Merged
merged 1 commit into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions application/logbackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1629,6 +1629,7 @@ bool LogBackend::getOutDirPath(const QString &path)
}
if (!bAvailable) {
qCWarning(logBackend) << qApp->translate("ExportMessage", "The export directory is not available. Please choose another directory for the export operation.");
qCWarning(logBackend) << "outPath: " << tmpPath;
return false;
}

Expand Down
28 changes: 17 additions & 11 deletions logViewerService/logviewerservice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,28 +197,34 @@ quint64 LogViewerService::getFileSize(const QString &filePath)
QStringList LogViewerService::whiteListOutPaths()
{
QStringList paths;
// 获取当前用户家目录
QString homePath = getAppUserHomePath();
if (!homePath.isEmpty())
paths.push_back(homePath);
// 获取用户家目录
QStringList homeList = getHomePaths();
if (!homeList.isEmpty())
paths << homeList;
// 获取外设挂载可写路径(包括smb路径)
paths << getExternalDevPaths();
// 获取临时目录
paths.push_back("/tmp");
return paths;
}

// 获取应用当前登录用户家目录
QString LogViewerService::getAppUserHomePath()
// 获取用户家目录
QStringList LogViewerService::getHomePaths()
{
QStringList homeList;

if (!calledFromDBus()) {
return "";
return homeList;
}

QFileInfoList infoList = QDir("/home").entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot);
for (auto info : infoList) {
if (info.isDir())
homeList.push_back(info.absoluteFilePath());
}

uint uid = connection().interface()->serviceUid(message().service()).value();
struct passwd* pwd = getpwuid(uid);
QString homePath = "/home/" + QString(pwd->pw_name);
return homePath;
qInfo() << "homeList: " << homeList;
return homeList;
}

// 获取外设挂载路径
Expand Down
8 changes: 4 additions & 4 deletions logViewerService/logviewerservice.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ public Q_SLOTS:
Q_SCRIPTABLE quint64 getFileSize(const QString &filePath);
Q_SCRIPTABLE QStringList whiteListOutPaths();

private:
// 获取应用当前登录用户家目录
QString getAppUserHomePath();
//获取外设挂载路径(包括smb路径)
public:
// 获取用户家目录
QStringList getHomePaths();
// 获取外设挂载路径(包括smb路径)
QStringList getExternalDevPaths();
QList<QExplicitlySharedDataPointer<DGioMount>> getMounts_safe();
private:
Expand Down
Loading