65 lines
2.4 KiB
Diff
65 lines
2.4 KiB
Diff
|
|
From 0ee8078d05e8fd67251b20383fc5b3cf04aedfb1 Mon Sep 17 00:00:00 2001
|
||
|
|
From: chenjiayi <chenjiayi22@huawei.com>
|
||
|
|
Date: Fri, 17 Nov 2023 01:20:21 +0800
|
||
|
|
Subject: [PATCH 069/103] fix(devmaster): cache the parsed user and group
|
||
|
|
|
||
|
|
The previously parsed user and group should be cached to avoid repeatedly
|
||
|
|
parsed later. Also fix and open the corresponding test case that is ignored
|
||
|
|
previously.
|
||
|
|
---
|
||
|
|
exts/devmaster/src/lib/rules/rules_load.rs | 21 ++++++++++++++-------
|
||
|
|
1 file changed, 14 insertions(+), 7 deletions(-)
|
||
|
|
|
||
|
|
diff --git a/exts/devmaster/src/lib/rules/rules_load.rs b/exts/devmaster/src/lib/rules/rules_load.rs
|
||
|
|
index 19b7aaa4..a4535b52 100644
|
||
|
|
--- a/exts/devmaster/src/lib/rules/rules_load.rs
|
||
|
|
+++ b/exts/devmaster/src/lib/rules/rules_load.rs
|
||
|
|
@@ -133,7 +133,10 @@ impl Rules {
|
||
|
|
|
||
|
|
match User::from_name(username) {
|
||
|
|
Ok(user) => match user {
|
||
|
|
- Some(u) => Ok(u),
|
||
|
|
+ Some(u) => {
|
||
|
|
+ self.users.insert(username.to_string(), u.clone());
|
||
|
|
+ Ok(u)
|
||
|
|
+ }
|
||
|
|
None => Err(Error::RulesLoadError {
|
||
|
|
msg: format!("The user name {} has no credential.", username),
|
||
|
|
}),
|
||
|
|
@@ -152,7 +155,10 @@ impl Rules {
|
||
|
|
|
||
|
|
match Group::from_name(groupname) {
|
||
|
|
Ok(group) => match group {
|
||
|
|
- Some(g) => Ok(g),
|
||
|
|
+ Some(g) => {
|
||
|
|
+ self.groups.insert(groupname.to_string(), g.clone());
|
||
|
|
+ Ok(g)
|
||
|
|
+ }
|
||
|
|
None => Err(Error::RulesLoadError {
|
||
|
|
msg: format!("The group name {} has no credential.", groupname),
|
||
|
|
}),
|
||
|
|
@@ -1983,14 +1989,15 @@ SYMLINK += \"test111111\"",
|
||
|
|
}
|
||
|
|
|
||
|
|
#[test]
|
||
|
|
- #[ignore]
|
||
|
|
- fn test_resolve_user() {
|
||
|
|
+ fn test_resolve_user_group() {
|
||
|
|
let mut rules = Rules::new(vec![], ResolveNameTime::Early);
|
||
|
|
- assert!(rules.resolve_user("tss").is_ok());
|
||
|
|
assert!(rules.resolve_user("root").is_ok());
|
||
|
|
- assert!(rules.users.contains_key("tss"));
|
||
|
|
assert!(rules.users.contains_key("root"));
|
||
|
|
- assert!(rules.resolve_user("cjy").is_err());
|
||
|
|
+ assert!(rules.resolve_user("abcdefg").is_err());
|
||
|
|
+
|
||
|
|
+ assert!(rules.resolve_group("root").is_ok());
|
||
|
|
+ assert!(rules.groups.contains_key("root"));
|
||
|
|
+ assert!(rules.resolve_group("abcdefg").is_err());
|
||
|
|
}
|
||
|
|
|
||
|
|
#[test]
|
||
|
|
--
|
||
|
|
2.33.0
|
||
|
|
|