#include <string>
#include <sys/types.h>
#include <vector>
-#include <deque>
+#include <deque>
+#include <cerrno>
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)