From: Caisking <3449750381@qq.com> Date: Tue, 8 Oct 2024 10:14:18 +0000 (+0800) Subject: 系统:修改无死机文件显示 X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=23e5fb03335c72bd639557beaf5361fc6b8fc1b8;p=mirrors%2FFD230.git 系统:修改无死机文件显示 --- diff --git a/code/sdk/application/wearable/service/msg_center/src/notify/debug_output_notification/debug_output_notification.cpp b/code/sdk/application/wearable/service/msg_center/src/notify/debug_output_notification/debug_output_notification.cpp index 8a83b9197..06101ea20 100644 --- a/code/sdk/application/wearable/service/msg_center/src/notify/debug_output_notification/debug_output_notification.cpp +++ b/code/sdk/application/wearable/service/msg_center/src/notify/debug_output_notification/debug_output_notification.cpp @@ -42,7 +42,8 @@ #include #include #include -#include +#include +#include namespace OHOS { @@ -286,27 +287,32 @@ namespace OHOS return oss.str(); } - // 死机文件名称列表 - static const char *SHUTDOWN_PATH = "/user/tar"; - std::string DebugOutputViewEventListener::get_shutdown_info() { - std::ostringstream oss; + static const char *SHUTDOWN_PATH = "/user/tar"; - // 打开目录 - DIR *dir = opendir(SHUTDOWN_PATH); - if (dir == nullptr) { - return "死机目录不存在或者目录下不存在文件"; - } + std::string DebugOutputViewEventListener::get_shutdown_info() { + std::ostringstream oss; - struct dirent *entry; - while ((entry = readdir(dir)) != nullptr) { - // 跳过. 和 .. - if (entry->d_name[0] != '.') { - oss << entry->d_name << "\n"; // 逐行添加 - } - } + // 打开目录 + DIR *dir = opendir(SHUTDOWN_PATH); + if (dir == nullptr) { + return "死机目录不存在: " + std::string(strerror(errno)); + } + + struct dirent *entry; + while ((entry = readdir(dir)) != nullptr) { + // 跳过. 和 .. + if (entry->d_name[0] != '.') { + oss << entry->d_name << "\n"; // 逐行添加 + } + } + + closedir(dir); // 关闭目录 + + if (oss.str().empty()) { + return "无死机文件"; + } - closedir(dir); // 关闭目录 - return oss.str(); // 返回以换行符分隔的文件名字符串 + return oss.str(); // 返回以换行符分隔的文件名字符串 } bool DebugOutputViewEventListener::OnClick(OHOS::UIView &view, const OHOS::ClickEvent &event)