Skip to content

Commit 3c2246f

Browse files
authored
Fix task log parsing error handling and bump to v0.6.1 (#123)
* fix(cache): 改进任务日志读取的错误处理并添加兼容性测试 - 在`task_log`方法中,将直接使用`unwrap`改为使用`match` 进行错误处理,当读取或解析失败时记录警告并返回默认的`TaskLog` - 在`TaskLog`结构体的`build_time`字段上添加`default` 属性,以支持反序列化旧版本中缺失该字段的任务日志 - 添加单元测试`should_deserialize_legacy_task_log_without_build_timestamp` ,确保能正确读取旧格式的任务日志 Signed-off-by: longjin <longjin@dragonos.org> * chore: bump version to 0.6.1 Signed-off-by: longjin <longjin@DragonOS.org> --------- Signed-off-by: longjin <longjin@dragonos.org> Signed-off-by: longjin <longjin@DragonOS.org>
1 parent 36d6208 commit 3c2246f

8 files changed

Lines changed: 47 additions & 18 deletions

File tree

Cargo.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ DADK是一个Rust程序,您可以通过Cargo来安装DADK。
3030
cargo install --git https://github.com/DragonOS-Community/DADK.git
3131

3232
# 或安装指定版本(推荐与DragonOS分支匹配)
33-
cargo install --git https://git.mirrors.dragonos.org.cn/DragonOS-Community/DADK.git --tag v0.6.0 --locked
33+
cargo install --git https://git.mirrors.dragonos.org.cn/DragonOS-Community/DADK.git --tag v0.6.1 --locked
3434

3535

3636
```

dadk-config/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "dadk-config"
3-
version = "0.6.0"
3+
version = "0.6.1"
44
edition = "2021"
55
authors = [
66
"longjin <longjin@DragonOS.org>",

dadk-user/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "dadk-user"
3-
version = "0.6.0"
3+
version = "0.6.1"
44
edition = "2021"
55
description = "DragonOS Application Development Kit - user prog build"
66
license = "GPL-2.0-only"
@@ -9,7 +9,7 @@ license = "GPL-2.0-only"
99
anyhow = { version = "1.0.100", features = ["std", "backtrace"] }
1010
chrono = { version = "=0.4.35", features = ["serde"] }
1111
clap = { version = "=4.5.20", features = ["derive"] }
12-
dadk-config = { version = "0.6.0", path = "../dadk-config" }
12+
dadk-config = { version = "0.6.1", path = "../dadk-config" }
1313
derive_builder = "0.20.0"
1414
lazy_static = "1.4.0"
1515
log = "0.4.17"

dadk-user/src/executor/cache.rs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::{
33
sync::{Arc, Once},
44
};
55

6-
use log::info;
6+
use log::{info, warn};
77

88
use crate::{
99
parser::{
@@ -255,9 +255,25 @@ impl TaskDataDir {
255255
pub fn task_log(&self) -> TaskLog {
256256
let path = self.dir.path.join(Self::TASK_LOG_FILE_NAME);
257257
if path.exists() {
258-
let content = std::fs::read_to_string(&path).unwrap();
259-
let task_log: TaskLog = toml::from_str(&content).unwrap();
260-
return task_log;
258+
match std::fs::read_to_string(&path) {
259+
Ok(content) => match toml::from_str(&content) {
260+
Ok(task_log) => return task_log,
261+
Err(e) => {
262+
warn!(
263+
"Failed to parse task log at {:?}: {}. Use default task log instead.",
264+
path, e
265+
);
266+
return TaskLog::new();
267+
}
268+
},
269+
Err(e) => {
270+
warn!(
271+
"Failed to read task log at {:?}: {}. Use default task log instead.",
272+
path, e
273+
);
274+
return TaskLog::new();
275+
}
276+
}
261277
} else {
262278
return TaskLog::new();
263279
}

dadk-user/src/parser/task_log.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use serde::{Deserialize, Deserializer, Serialize};
1111
pub struct TaskLog {
1212
/// 任务执行完成时间
1313
#[serde(
14+
default,
1415
deserialize_with = "ok_or_default",
1516
skip_serializing_if = "Option::is_none"
1617
)]
@@ -150,3 +151,15 @@ impl<'de> Deserialize<'de> for InstallStatus {
150151
}
151152
}
152153
}
154+
155+
#[cfg(test)]
156+
mod tests {
157+
use super::TaskLog;
158+
159+
#[test]
160+
fn should_deserialize_legacy_task_log_without_build_timestamp() {
161+
let content = "dadk_config_timestamp = \"2026-02-09T19:42:17.464516620Z\"\n";
162+
let task_log: TaskLog = toml::from_str(content).expect("legacy task_log must be readable");
163+
assert!(task_log.build_time().is_none());
164+
}
165+
}

dadk/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ authors = [
66
"xuzihao <xuzihao@DragonOS.org>"
77
]
88

9-
version = "0.6.0"
9+
version = "0.6.1"
1010
edition = "2021"
1111
description = "DragonOS Application Development Kit\nDragonOS应用开发工具"
1212
license = "GPL-2.0-only"
@@ -33,8 +33,8 @@ insiders = []
3333
anyhow = { version = "1.0.100", features = ["std", "backtrace"] }
3434
clap = { version = "4.5.20", features = ["derive"] }
3535
crossbeam = "0.8.4"
36-
dadk-config = { version = "0.6.0", path = "../dadk-config" }
37-
dadk-user = { version = "0.6.0", path = "../dadk-user" }
36+
dadk-config = { version = "0.6.1", path = "../dadk-config" }
37+
dadk-user = { version = "0.6.1", path = "../dadk-user" }
3838
derive_builder = "0.20.0"
3939
env_logger = { workspace = true }
4040
humantime = "2.1.0"

docs/user-manual/quickstart.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,21 @@ DADK是一个用于管理DragonOS的应用编译打包的工具。您可以通
1313

1414

1515
```
16-
MIN_DADK_VERSION = 0.6.0
16+
MIN_DADK_VERSION = 0.6.1
1717
```
1818

1919
::: warning 注意版本兼容性
20-
请确保您使用的 dadk 版本与 DragonOS 当前分支要求一致(当前推荐 `v0.6.0`)。
20+
请确保您使用的 dadk 版本与 DragonOS 当前分支要求一致(当前推荐 `v0.6.1`)。
2121
:::
2222

2323
您可以通过以下命令安装dadk:
2424
```shell
2525
cargo install --git https://git.mirrors.dragonos.org.cn/DragonOS-Community/DADK.git --tag <版本号> --locked
2626
```
2727

28-
比如,对于0.6.0版本,您可以使用以下命令安装: `(注意版本号前面有个v)`
28+
比如,对于0.6.1版本,您可以使用以下命令安装: `(注意版本号前面有个v)`
2929
```shell
30-
cargo install --git https://git.mirrors.dragonos.org.cn/DragonOS-Community/DADK.git --tag v0.6.0 --locked
30+
cargo install --git https://git.mirrors.dragonos.org.cn/DragonOS-Community/DADK.git --tag v0.6.1 --locked
3131
```
3232

3333
## RootFS(ext4 + Docker base)

0 commit comments

Comments
 (0)