feat(log): App日志目录扁平化为 MeowOS/logs/<包名>/ (agent-198, 用户定案) — launcher MEOW_LOG_DIR 注入改 logs/<appid>+mkdir_p; SDK meow_ui_log.c 去 apps/ 嵌套; 卡可用时一次性迁移 logs/apps/* 并入新路径; APPS.md/APP_LOG_MANAGER.md 同步
launcher→61f6b0db; files→ac2c2781; 编译0warning(新增代码)
This commit is contained in:
1 parent
32a6a8ed1e
commit
5f7e7542bd
6 files changed
+132
-5
No files matched your search
@@ -2,6 +2,9 @@
|
||||
/* 本文件由拆分工具从 meow_launcherd.c 按职责搬移;逻辑与原文 0-diff(仅 static 可见性按跨模块需求调整)。*/
|
||||
#include "meow_launcher_internal.h"
|
||||
|
||||
/* M2.x 应用日志目录简化:一次性迁移 logs/apps/<id>/logs → logs/<id>(定义见下,log_open_card 先调用)。 */
|
||||
static void log_migrate_apps(void);
|
||||
|
||||
int log_fd = -1; /* file log fd on the TF card */
|
||||
|
||||
char log_dir[256] = ""; /* "MeowOS/logs" on card, or "" */
|
||||
@@ -133,6 +136,7 @@ int log_open_card(void)
|
||||
{
|
||||
if (log_fd >= 0) return 0;
|
||||
if (!card_available()) return -1;
|
||||
log_migrate_apps(); /* M2.x 一次性迁移:logs/apps/<id>/logs → logs/<id>(幂等,见下) */
|
||||
char ts[64];
|
||||
boot_timestamp(ts, sizeof ts);
|
||||
snprintf(log_dir, sizeof log_dir, "%s", LOG_DIR_CARD);
|
||||
@@ -144,6 +148,117 @@ int log_open_card(void)
|
||||
}
|
||||
|
||||
|
||||
/* M2.x 应用日志目录简化:mkdir -p(幂等,已存在 EEXIST 视为成功)。返回 0=成功 -1=失败。
|
||||
* 供 launcher 为每 App 建新布局日志目录 logs/<id>/ 用(沿用 SDK 同款逐分量 mkdir)。 */
|
||||
int meow_mkdir_p(const char *path)
|
||||
{
|
||||
char tmp[256];
|
||||
size_t len, i;
|
||||
if (!path || !path[0] || strlen(path) >= sizeof tmp) return -1;
|
||||
len = strlen(path);
|
||||
memcpy(tmp, path, len + 1);
|
||||
if (tmp[len - 1] == '/') tmp[len - 1] = '\0'; /* 去尾斜杠 */
|
||||
for (i = 1; i <= strlen(tmp); i++) {
|
||||
if (tmp[i] == '/' || tmp[i] == '\0') {
|
||||
char ch = tmp[i];
|
||||
tmp[i] = '\0';
|
||||
if (tmp[0] && mkdir(tmp, 0755) != 0 && errno != EEXIST) return -1;
|
||||
tmp[i] = ch;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* M2.x 一次性迁移(幂等,代码可后续移除):旧布局 LOG_DIR_CARD/apps/<id>/logs/<file>.log
|
||||
* 并入新布局 LOG_DIR_CARD/<id>/<file>.log,然后删除旧 apps/ 整树。卡可用时随 log_open_card
|
||||
* 跑一次;apps/ 已不存在则直接返回。同卡同 fs,文件用 rename() 移动(目标同名被覆盖——迁移
|
||||
* 内只挪旧文件,不写新日志)。总容量上限纪律不变:应用日志仍由 SDK 按 App 50MB 清理,boot 日志
|
||||
* 仍走 log_cleanup_old()。 */
|
||||
static void log_rm_rf(const char *path)
|
||||
{
|
||||
struct stat st;
|
||||
if (stat(path, &st) != 0) return;
|
||||
if (S_ISDIR(st.st_mode)) {
|
||||
DIR *d = opendir(path);
|
||||
if (d) {
|
||||
struct dirent *e;
|
||||
while ((e = readdir(d)) != NULL) {
|
||||
if (e->d_name[0] == '.' && (e->d_name[1] == '\0' ||
|
||||
(e->d_name[1] == '.' && e->d_name[2] == '\0'))) continue;
|
||||
char sub[512];
|
||||
snprintf(sub, sizeof sub, "%s/%s", path, e->d_name);
|
||||
log_rm_rf(sub);
|
||||
}
|
||||
closedir(d);
|
||||
}
|
||||
rmdir(path);
|
||||
} else {
|
||||
unlink(path);
|
||||
}
|
||||
}
|
||||
|
||||
static void log_migrate_apps(void)
|
||||
{
|
||||
char old_root[512], old_dir[512], old_logs[512], new_dir[512];
|
||||
DIR *d, *dl, *dd;
|
||||
struct dirent *e;
|
||||
|
||||
snprintf(old_root, sizeof old_root, "%s/apps", LOG_DIR_CARD);
|
||||
d = opendir(old_root);
|
||||
if (!d) return; /* 旧路径不存在,无需迁移 */
|
||||
|
||||
while ((e = readdir(d)) != NULL) {
|
||||
struct stat st;
|
||||
if (e->d_name[0] == '.') continue;
|
||||
snprintf(old_dir, sizeof old_dir, "%s/%s", old_root, e->d_name);
|
||||
if (stat(old_dir, &st) != 0 || !S_ISDIR(st.st_mode)) continue;
|
||||
|
||||
snprintf(new_dir, sizeof new_dir, "%s/%s", LOG_DIR_CARD, e->d_name);
|
||||
if (meow_mkdir_p(new_dir) != 0) continue; /* 新目录建不了,跳过该 App */
|
||||
|
||||
/* 旧布局 apps/<id>/logs/<file>.log → logs/<id>/<file>.log */
|
||||
snprintf(old_logs, sizeof old_logs, "%s/logs", old_dir);
|
||||
dl = opendir(old_logs);
|
||||
if (dl) {
|
||||
struct dirent *el;
|
||||
while ((el = readdir(dl)) != NULL) {
|
||||
struct stat stl;
|
||||
char src[512], dst[512];
|
||||
if (el->d_name[0] == '.') continue;
|
||||
snprintf(src, sizeof src, "%s/%s", old_logs, el->d_name);
|
||||
if (stat(src, &stl) != 0 || !S_ISREG(stl.st_mode)) continue;
|
||||
snprintf(dst, sizeof dst, "%s/%s", new_dir, el->d_name);
|
||||
rename(src, dst);
|
||||
}
|
||||
closedir(dl);
|
||||
}
|
||||
|
||||
/* 早期设计若直接把 .log 散在 apps/<id>/ 下,一并并入(跳过已处理的 logs/ 子目录) */
|
||||
dd = opendir(old_dir);
|
||||
if (dd) {
|
||||
struct dirent *ed;
|
||||
while ((ed = readdir(dd)) != NULL) {
|
||||
struct stat stf;
|
||||
char src[512], dst[512];
|
||||
if (ed->d_name[0] == '.') continue;
|
||||
if (strcmp(ed->d_name, "logs") == 0) continue;
|
||||
snprintf(src, sizeof src, "%s/%s", old_dir, ed->d_name);
|
||||
if (stat(src, &stf) != 0 || !S_ISREG(stf.st_mode)) continue;
|
||||
snprintf(dst, sizeof dst, "%s/%s", new_dir, ed->d_name);
|
||||
rename(src, dst);
|
||||
}
|
||||
closedir(dd);
|
||||
}
|
||||
|
||||
log_rm_rf(old_dir);
|
||||
}
|
||||
closedir(d);
|
||||
rmdir(old_root); /* apps/ 清空则删;非空则忽略 */
|
||||
fprintf(stderr, "log_migrate: logs/apps/* -> logs/<id> done\n");
|
||||
}
|
||||
|
||||
|
||||
/* flush the /tmp boot buffer into the file log (once the card mounts) */
|
||||
void log_poll_card(void)
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user