系统:修改无死机文件显示
authorCaisking <3449750381@qq.com>
Tue, 8 Oct 2024 10:14:18 +0000 (18:14 +0800)
committerCaisking <3449750381@qq.com>
Tue, 8 Oct 2024 10:14:18 +0000 (18:14 +0800)
code/sdk/application/wearable/service/msg_center/src/notify/debug_output_notification/debug_output_notification.cpp

index 8a83b91..06101ea 100644 (file)
@@ -42,7 +42,8 @@
 #include <string>
 #include <sys/types.h>
 #include <vector>
-#include <deque> 
+#include <deque>
+#include <cerrno>
 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)