Przeglądaj źródła

fix(misc): format in other crates

Samuka007 2 tygodni temu
rodzic
commit
f597cb4bc0

+ 0 - 2
crates/test_base/src/dadk_config.rs

@@ -42,8 +42,6 @@ impl TestContext for DadkConfigTestContext {
         // 设置workdir
         std::env::set_current_dir(&test_base_path).expect("Failed to setup test base path");
 
-        
-
         DadkConfigTestContext { test_base_path }
     }
 }

+ 1 - 1
dadk-config/src/common/target_arch.rs

@@ -83,7 +83,7 @@ impl Display for TargetArch {
             TargetArch::X86_64 => write!(f, "x86_64"),
             TargetArch::RiscV64 => write!(f, "riscv64"),
             TargetArch::AArch64 => write!(f, "aarch64"),
-            TargetArch::LoongArch64 => write!(f, "loongarch64"),    
+            TargetArch::LoongArch64 => write!(f, "loongarch64"),
         }
     }
 }

+ 5 - 2
dadk-config/src/rootfs/mod.rs

@@ -3,7 +3,10 @@ pub mod partition;
 
 mod utils;
 
-use std::{fs, path::PathBuf};
+use std::{
+    fs,
+    path::{Path, PathBuf},
+};
 
 use anyhow::Result;
 use fstype::FsType;
@@ -20,7 +23,7 @@ pub struct RootFSConfigFile {
 
 impl RootFSConfigFile {
     pub const LBA_SIZE: usize = 512;
-    pub fn load(path: &PathBuf) -> Result<Self> {
+    pub fn load(path: &Path) -> Result<Self> {
         // 读取文件内容
         let content = fs::read_to_string(path)?;
         Self::load_from_str(&content)

+ 2 - 2
dadk-user/src/executor/cache.rs

@@ -1,5 +1,5 @@
 use std::{
-    path::PathBuf,
+    path::{Path, PathBuf},
     sync::{Arc, Once},
 };
 
@@ -143,7 +143,7 @@ impl CacheDir {
                 )
             }
         };
-        abs_path(&PathBuf::from(cache_dir))
+        abs_path(Path::new(&cache_dir))
     }
 
     pub fn build_dir(entity: Arc<SchedEntity>) -> Result<PathBuf, ExecutorError> {

+ 22 - 25
dadk-user/src/executor/mod.rs

@@ -1,7 +1,7 @@
 use std::{
     collections::{BTreeMap, VecDeque},
     env::Vars,
-    path::PathBuf,
+    path::{Path, PathBuf},
     process::{Command, Stdio},
     sync::{Arc, RwLock},
     time::SystemTime,
@@ -314,8 +314,7 @@ impl Executor {
 
         // 拷贝构建结果到安装路径
         let build_dir: PathBuf = self.build_dir.path.clone();
-        FileUtils::copy_dir_all(&build_dir, &install_path)
-            .map_err(ExecutorError::InstallError)?;
+        FileUtils::copy_dir_all(&build_dir, &install_path).map_err(ExecutorError::InstallError)?;
         info!("Task {} installed.", self.entity.task().name_version());
 
         Ok(())
@@ -415,7 +414,7 @@ impl Executor {
         if let Some(local_path) = self.entity.task().source_path() {
             return local_path;
         }
-        return self.source_dir.as_ref().unwrap().path.clone();
+        self.source_dir.as_ref().unwrap().path.clone()
     }
 
     fn task_log(&self) -> TaskLog {
@@ -718,11 +717,11 @@ fn create_global_env_list(
 /// * `last_modified` - 最后的更新时间
 /// * `build_time` - 构建时间
 fn last_modified_time(
-    path: &PathBuf,
+    path: &Path,
     build_time: &DateTime<Utc>,
 ) -> Result<DateTime<Utc>, ExecutorError> {
     let mut queue = VecDeque::new();
-    queue.push_back(path.clone());
+    queue.push_back(path.to_path_buf());
 
     let mut last_modified = DateTime::<Utc>::from(SystemTime::UNIX_EPOCH);
 
@@ -732,28 +731,26 @@ fn last_modified_time(
             .map_err(|e| ExecutorError::InstallError(e.to_string()))?;
 
         if metadata.is_dir() {
-            for r in std::fs::read_dir(&current_path).unwrap() {
-                if let Ok(entry) = r {
-                    // 忽略编译产物目录
-                    if entry.file_name() == "target" {
-                        continue;
-                    }
+            for entry in std::fs::read_dir(&current_path).unwrap().flatten() {
+                // 忽略编译产物目录
+                if entry.file_name() == "target" {
+                    continue;
+                }
 
-                    let entry_path = entry.path();
-                    let entry_metadata = entry.metadata().unwrap();
-                    // 比较文件的修改时间和last_modified,取最大值
-                    let file_modified = DateTime::<Utc>::from(entry_metadata.modified().unwrap());
-                    last_modified = std::cmp::max(last_modified, file_modified);
+                let entry_path = entry.path();
+                let entry_metadata = entry.metadata().unwrap();
+                // 比较文件的修改时间和last_modified,取最大值
+                let file_modified = DateTime::<Utc>::from(entry_metadata.modified().unwrap());
+                last_modified = std::cmp::max(last_modified, file_modified);
 
-                    // 如果其中某一个文件的修改时间在build_time之后,则直接返回,不用继续搜索
-                    if last_modified > *build_time {
-                        return Ok(last_modified);
-                    }
+                // 如果其中某一个文件的修改时间在build_time之后,则直接返回,不用继续搜索
+                if last_modified > *build_time {
+                    return Ok(last_modified);
+                }
 
-                    if entry_metadata.is_dir() {
-                        // 如果是子目录,则将其加入队列
-                        queue.push_back(entry_path);
-                    }
+                if entry_metadata.is_dir() {
+                    // 如果是子目录,则将其加入队列
+                    queue.push_back(entry_path);
                 }
             }
         } else {

+ 1 - 2
dadk-user/src/executor/tests.rs

@@ -38,8 +38,7 @@ fn setup_executor<T: TestContextExt>(config_file: PathBuf, ctx: &T) -> Executor
 
     assert!(executor.is_ok(), "Create executor error: {:?}", executor);
 
-    let executor = executor.unwrap();
-    executor
+    executor.unwrap()
 }
 
 /// 测试能否正确设置本地环境变量

+ 2 - 2
dadk-user/src/parser/mod.rs

@@ -160,7 +160,7 @@ impl Parser {
 
         while let Some(dir) = dir_queue.pop() {
             // 扫描目录,找到所有*.dadk文件
-            
+
             let entries: ReadDir = std::fs::read_dir(&dir)?;
 
             for entry in entries {
@@ -175,7 +175,7 @@ impl Parser {
                         continue;
                     }
                     let extension: &std::ffi::OsStr = extension.unwrap();
-                    if extension.to_ascii_lowercase() != "toml" {
+                    if !extension.eq_ignore_ascii_case("toml") {
                         continue;
                     }
                     // 找到一个配置文件, 加入列表

+ 5 - 13
dadk-user/src/parser/task.rs

@@ -95,7 +95,7 @@ impl DADKTask {
     /// 从环境变量`ARCH`中获取,如果没有设置,则默认为`x86_64`
     pub fn default_target_arch() -> TargetArch {
         let s = std::env::var("ARCH").unwrap_or("x86_64".to_string());
-        return TargetArch::try_from(s.as_str()).unwrap();
+        TargetArch::try_from(s.as_str()).unwrap()
     }
 
     fn default_target_arch_vec() -> Vec<TargetArch> {
@@ -215,20 +215,12 @@ impl DADKTask {
     pub fn source_path(&self) -> Option<PathBuf> {
         match &self.task_type {
             TaskType::BuildFromSource(cs) => match cs {
-                CodeSource::Local(lc) => {
-                    return Some(lc.path().clone());
-                }
-                _ => {
-                    None
-                }
+                CodeSource::Local(lc) => Some(lc.path().clone()),
+                _ => None,
             },
             TaskType::InstallFromPrebuilt(ps) => match ps {
-                PrebuiltSource::Local(lc) => {
-                    return Some(lc.path().clone());
-                }
-                _ => {
-                    None
-                }
+                PrebuiltSource::Local(lc) => Some(lc.path().clone()),
+                _ => None,
             },
         }
     }

+ 2 - 1
dadk-user/src/scheduler/mod.rs

@@ -572,7 +572,8 @@ impl Scheduler {
                 let name_version = (dependency.name.clone(), dependency.version.clone());
                 if self
                     .target
-                    .get_by_name_version(&name_version.0, &name_version.1).is_none()
+                    .get_by_name_version(&name_version.0, &name_version.1)
+                    .is_none()
                 {
                     return Err(SchedulerError::DependencyNotFound(
                         entity.clone(),

+ 4 - 4
dadk-user/src/utils/lazy_init.rs

@@ -90,7 +90,7 @@ impl<T> Lazy<T> {
     /// This will initialize the value if it has not yet been initialized.
     pub fn get(&self) -> &T {
         self.ensure();
-        return unsafe { self.get_unchecked() };
+        unsafe { self.get_unchecked() }
     }
 
     /// Returns a reference to the value if it has been initialized.
@@ -108,7 +108,7 @@ impl<T> Lazy<T> {
     /// been initialized.
     pub fn get_mut(&mut self) -> &mut T {
         self.ensure();
-        return unsafe { self.get_mut_unchecked() };
+        unsafe { self.get_mut_unchecked() }
     }
 
     #[inline(always)]
@@ -127,14 +127,14 @@ impl<T> Deref for Lazy<T> {
 
     #[inline(always)]
     fn deref(&self) -> &T {
-        return self.get();
+        self.get()
     }
 }
 
 impl<T> DerefMut for Lazy<T> {
     #[inline(always)]
     fn deref_mut(&mut self) -> &mut T {
-        return self.get_mut();
+        self.get_mut()
     }
 }
 

+ 2 - 2
dadk-user/src/utils/path.rs

@@ -1,7 +1,7 @@
-use std::path::PathBuf;
+use std::path::{Path, PathBuf};
 
 /// 获取给定路径的绝对路径
-pub fn abs_path(path: &PathBuf) -> PathBuf {
+pub fn abs_path(path: &Path) -> PathBuf {
     if path.is_absolute() {
         path.to_path_buf()
     } else {

+ 1 - 1
dadk-user/src/utils/stdio.rs

@@ -4,7 +4,7 @@ impl StdioUtils {
     /// # 将标准错误输出转换为行列表
     pub fn stderr_to_lines(stderr: &[u8]) -> Vec<String> {
         let stderr = String::from_utf8_lossy(stderr);
-        return stderr.lines().map(|s| s.to_string()).collect();
+        stderr.lines().map(|s| s.to_string()).collect()
     }
 
     /// 获取标准错误输出的最后n行, 以字符串形式返回.