Skip to content

Commit 033be80

Browse files
committed
Refactor: Use QTemporaryDir for temporary log export
Replaced the manual creation and deletion of the temporary directory for operational logs with QTemporaryDir. QTemporaryDir provides a more robust and safer mechanism for handling temporary files and directories. Task: https://pms.uniontech.com/task-view-381443.html
1 parent fe1eb84 commit 033be80

File tree

3 files changed

+9
-11
lines changed

3 files changed

+9
-11
lines changed

application/configs/coredump-reporter.service

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,3 @@ InaccessiblePaths=-/etc/pam.d
1212
InaccessiblePaths=-/usr/share/uadp
1313
InaccessiblePaths=-/etc/sudoers
1414
InaccessiblePaths=-/etc/sudoers.d
15-
MemoryMax=8G

application/logallexportthread.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -471,9 +471,10 @@ void LogAllExportThread::run()
471471
if (!m_cancel.load()) {
472472
// Create temporary directory for ops logs
473473
QString userHomePath = QStandardPaths::writableLocation(QStandardPaths::HomeLocation);
474-
QString opsLogPath = QDir::tempPath() + "/deepin-log-viewer-ops-logs-" + QString::number(QDateTime::currentMSecsSinceEpoch());
474+
QTemporaryDir tempDir(QDir::tempPath() + "/XXXXXX");
475475

476-
if (QDir().mkpath(opsLogPath)) {
476+
if (tempDir.isValid()) {
477+
QString opsLogPath = tempDir.path();
477478
DLDBusHandler::instance(this)->exportOpsLog(opsLogPath, userHomePath);
478479
completedTasks += 5;
479480
emit updatecurrentProcess(completedTasks);
@@ -538,15 +539,14 @@ void LogAllExportThread::run()
538539
}
539540
completedTasks += 2;
540541
emit updatecurrentProcess(completedTasks);
541-
// Clean up temporary directory
542-
if (!Utils::deleteDir(opsLogPath)) {
543-
qCWarning(logApp) << "Failed to remove temporary ops log directory:" << opsLogPath;
544-
}
545-
completedTasks += 1;
546-
emit updatecurrentProcess(completedTasks);
547542
} else {
548-
qCCritical(logApp) << "Failed to create temporary ops log directory:" << opsLogPath;
543+
qCCritical(logApp) << "Failed to create temporary ops log directory";
544+
completedTasks += 9;
545+
emit updatecurrentProcess(completedTasks);
549546
}
547+
548+
completedTasks += 1;
549+
emit updatecurrentProcess(completedTasks);
550550
}
551551

552552
zipClose(m_zipFile, "Exported by Deepin Log Viewer");

logViewerService/assets/data/deepin-log-viewer-daemon.service

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ BusName=com.deepin.logviewer
99
ExecStart=/usr/lib/deepin-daemon/log-view-service
1010
# cap能力不能填为空,否则日志收集工具启动卡,并且不能查看/var/log下日志,建议cap能力不能为dbus必查项
1111
#CapabilityBoundingSet=~CAP_NET_RAW
12-
MemoryMax=8G
1312
# 非root有阻塞,deepin-daemon启动后不能通过/proc/pid/exe获取启动进程全路径,下一阶段再按deepin-dameon启动
1413
#User=deepin-daemon
1514
ProtectSystem=strict

0 commit comments

Comments
 (0)