Repository navigation
202510281922 master feat - #415
Merged
lzwind merged 6 commits intoOct 30, 2025
Merged
Conversation
-- Add ops log logic code for ops log. Log: add feature for ops logs Task: https://pms.uniontech.com/story-view-39399.html
-- Add dbus interface for get ops logs. Log: add feature for ops logs. Task: https://pms.uniontech.com/story-view-39399.html
-- Add ops log directory structure. Log: add feature for ops logs. Task: https://pms.uniontech.com/story-view-39399.html
-- Export apps logs for ops. Log: add feature for ops logs. Task: https://pms.uniontech.com/story-view-39399.html
-- Add system logs and kernel logs for ops. Log: add feature for ops logs. Task: https://pms.uniontech.com/story-view-39399.html
-- Export DDE logs. -- Export special platform logs. -- Export os version logs. -- Export deb verison logs. Log: add feature for ops logs. Task: https://pms.uniontech.com/story-view-39399.html
deepin pr auto review这是一个用于添加运维日志导出功能的代码变更。让我从多个角度分析这段代码:
改进建议:
// 替换 system() 调用,使用 QProcess
void Utils::exportSomeOpsLogs(const QString &outDir, const QString &userHomeDir)
{
// 验证输入参数
if (!QDir(outDir).exists() || !QDir(userHomeDir).exists()) {
qCCritical(logApp) << "Invalid directory paths";
return;
}
// 使用 QProcess 替代 system()
QProcess process;
// glxinfo
process.setWorkingDirectory(outDir + "/app/kwin");
process.start("glxinfo", QStringList{"-B"});
process.waitForFinished();
QFile file(outDir + "/app/kwin/glxinfo.log");
if (file.open(QIODevice::WriteOnly)) {
file.write(process.readAllStandardOutput());
}
// 其他命令类似处理...
}
// 使用异步方式处理文件操作
void OpsLogExport::copy_file_or_dir(const QString &src, const QString &dst_dir)
{
if (!QFile::exists(src)) return;
QFuture<void> future = QtConcurrent::run([=]() {
QDir().mkpath(dst_dir);
QFile::copy(src, dst_dir);
});
}
bool DLDBusHandler::exportOpsLog(const QString &outDir, const QString &userHomeDir)
{
// 参数验证
if (outDir.isEmpty() || userHomeDir.isEmpty()) {
qCCritical(logApp) << "Empty directory paths provided";
return false;
}
QDBusMessage message = QDBusMessage::createMethodCall(kLogExportService,
kLogExportPath,
kLogExportInterface,
"ExportOpsLog");
message << outDir << userHomeDir;
QDBusMessage reply = QDBusConnection::systemBus().call(message, QDBus::Block, 1200000);
if (reply.type() == QDBusMessage::ErrorMessage) {
qCCritical(logApp) << "DBus call failed:" << reply.errorMessage();
return false;
}
bool result = false;
const QDBusArgument &arg = reply.arguments().first().value<QDBusArgument>();
arg >> result;
return result;
}
// 使用配置文件管理路径和命令
class OpsLogConfig {
public:
static QString getAppLogPath(const QString &appName) {
static QMap<QString, QString> paths = {
{"deepin-defender", "~/.cache/deepin/deepin-defender/"},
// 其他应用路径...
};
return paths.value(appName);
}
static QStringList getSystemCommands() {
return {
"dmesg -T",
"journalctl",
// 其他系统命令...
};
}
};
// 使用更合理的权限设置
void OpsLogExport::setFilePermissions(const QString &path)
{
QFile file(path);
if (file.exists()) {
// 设置为 644 (rw-r--r--)
file.setPermissions(QFile::ReadOwner | QFile::WriteOwner |
QFile::ReadGroup | QFile::ReadOther);
}
}
// 使用 RAII 管理临时目录
class TempDirectory {
public:
TempDirectory(const QString &prefix) {
m_path = QDir::temp().filePath(prefix + QDateTime::currentDateTime().toString("yyyyMMddhhmmss"));
QDir().mkpath(m_path);
}
~TempDirectory() {
if (QDir(m_path).exists()) {
QDir(m_path).removeRecursively();
}
}
QString path() const { return m_path; }
private:
QString m_path;
};这些改进可以显著提高代码的安全性、性能和可维护性。建议在实施这些改进时,确保进行充分的测试,特别是涉及系统调用和文件操作的部分。 |
lzwind
approved these changes
Oct 30, 2025
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: GongHeng2017, lzwind The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.