Browse Source

解决warning (#24)

GnoCiYeH 1 year ago
parent
commit
76992bdb7f

+ 1 - 1
Cargo.toml

@@ -1,5 +1,5 @@
 [package]
-name = "DragonReach"
+name = "dragon_reach"
 version = "0.1.0"
 edition = "2021"
 

+ 3 - 0
src/executor/dep_graph/mod.rs

@@ -8,18 +8,21 @@ use crate::{
     unit::Unit,
 };
 
+#[allow(dead_code)]
 pub struct DepGraphNode {
     value: usize,
     edges: Vec<usize>,
     incoming_edges: Vec<usize>,
 }
 
+#[allow(dead_code)]
 pub struct DepGraph {
     nodes: Vec<DepGraphNode>,
     value: Vec<usize>,
 }
 
 // 提供拓扑排序方法,在启动服务时确定先后顺序
+#[allow(dead_code)]
 impl DepGraph {
     fn new() -> Self {
         return DepGraph {

+ 1 - 1
src/executor/mod.rs

@@ -4,9 +4,9 @@ pub mod service_executor;
 use crate::{
     error::runtime_error::{RuntimeError, RuntimeErrorType},
     manager::UnitManager,
-    unit::Unit,
 };
 
+#[allow(dead_code)]
 #[derive(Debug, Clone, Copy)]
 pub enum ExitStatus {
     Success,  // 成功退出

+ 2 - 0
src/manager/unit_manager/mod.rs

@@ -36,6 +36,7 @@ pub struct RunningTableManager {
     running_table: HashMap<usize, Child>,
 }
 
+#[allow(dead_code)]
 impl RunningTableManager {
     pub fn running_table(&self) -> &HashMap<usize, Child> {
         &self.running_table
@@ -50,6 +51,7 @@ pub struct UnitManager;
 
 unsafe impl Sync for UnitManager {}
 
+#[allow(dead_code)]
 impl UnitManager {
     /// 插入一条path到unit_id的映射
     pub fn insert_into_path_table(path: &str, unit: usize) {

+ 1 - 2
src/parse/mod.rs

@@ -273,8 +273,8 @@ impl UnitParser {
             //下面进行属性匹配
             //合并多行为一个属性的情况
             //最后一个字符为\,代表换行,将多行转换为一行统一解析
+            let mut templine = String::new();
             if lines[i].ends_with('\\') {
-                let mut templine = String::new();
                 while lines[i].ends_with('\\') {
                     let temp = &lines[i][..lines[i].len() - 1];
                     templine = format!("{} {}", templine, temp);
@@ -283,7 +283,6 @@ impl UnitParser {
                 templine = format!("{} {}", templine, lines[i]);
                 line = templine.as_str();
                 i += 1;
-                break;
             }
             //=号分割后第一个元素为属性,后面的均为值
             let (attr_str, val_str) = match line.find('=') {

+ 10 - 10
src/parse/parse_util/mod.rs

@@ -13,6 +13,7 @@ use std::{
 
 use super::{UnitParser, BASE_IEC, BASE_SI, SEC_UNIT_TABLE};
 
+#[allow(dead_code)]
 #[derive(PartialEq)]
 pub enum SizeBase {
     IEC,
@@ -21,6 +22,7 @@ pub enum SizeBase {
 
 pub struct UnitParseUtil;
 
+#[allow(dead_code)]
 impl UnitParseUtil {
     /// @brief 解析布尔值
     ///
@@ -147,14 +149,12 @@ impl UnitParseUtil {
         }
 
         let mtu: u32 = mtu as u32;
-
-        let mut min_mtu: u32 = 0;
         //判断mtu是否合法
-        if family == AF_INET6 {
-            min_mtu = IPV6_MIN_MTU;
-        } else if family == AF_INET {
-            min_mtu = IPV4_MIN_MTU;
-        } else {
+        if family == AF_INET6 && mtu < IPV6_MIN_MTU {
+            return Err(ParseError::new(ParseErrorType::ERANGE, String::new(), 0));
+        } else if family == AF_INET && mtu < IPV4_MIN_MTU {
+            return Err(ParseError::new(ParseErrorType::ERANGE, String::new(), 0));
+        } else if family != AF_INET6 || family != AF_INET {
             return Err(ParseError::new(ParseErrorType::EINVAL, String::new(), 0));
         }
 
@@ -491,7 +491,7 @@ impl UnitParseUtil {
             cmd_task.ignore = cmds[i].starts_with('-');
 
             //获取到一个CmdTask的路径部分
-            let mut path = String::new();
+            let path: String;
             if cmd_task.ignore {
                 path = String::from(&cmds[i][1..]);
             } else {
@@ -579,9 +579,9 @@ impl UnitParseUtil {
     /// @return 解析成功则返回Ok(u64),否则返回Err
     pub fn parse_sec(s: &str) -> Result<u64, ParseError> {
         //下列参数分别记录整数部分,小数部分以及单位
-        let mut integer: u64 = 0;
+        let integer: u64;
         let mut frac: u64 = 0;
-        let mut unit: &str = "";
+        let unit: &str;
 
         match s.find('.') {
             Some(idx) => {

+ 7 - 0
src/unit/mod.rs

@@ -105,6 +105,7 @@ pub trait Unit: Sync + Send + Debug {
 }
 
 //Unit状态
+#[allow(dead_code)]
 #[derive(Clone, Copy, Debug, PartialEq)]
 pub enum UnitState {
     Enabled,
@@ -114,6 +115,7 @@ pub enum UnitState {
 }
 
 //Unit类型
+#[allow(dead_code)]
 #[derive(Clone, Copy, PartialEq, Debug)]
 pub enum UnitType {
     Automount,
@@ -153,6 +155,7 @@ impl Default for BaseUnit {
     }
 }
 
+#[allow(dead_code)]
 impl BaseUnit {
     pub fn set_state(&mut self, state: UnitState) {
         self.state = state;
@@ -262,6 +265,7 @@ impl Default for UnitPart {
     }
 }
 
+#[allow(dead_code)]
 impl UnitPart {
     pub fn set_attr(&mut self, attr: &BaseUnitAttr, val: &str) -> Result<(), ParseError> {
         match attr {
@@ -421,6 +425,7 @@ impl Default for InstallPart {
     }
 }
 
+#[allow(dead_code)]
 impl InstallPart {
     pub fn set_attr(&mut self, attr: &InstallUnitAttr, val: &str) -> Result<(), ParseError> {
         match attr {
@@ -475,6 +480,7 @@ impl InstallPart {
     }
 }
 //对应Unit文件的各种属性
+#[allow(dead_code)]
 pub enum BaseUnitAttr {
     None,
 
@@ -501,6 +507,7 @@ pub enum BaseUnitAttr {
     Conflicts,
 }
 
+#[allow(dead_code)]
 pub enum InstallUnitAttr {
     None,
     //Install段

+ 2 - 0
src/unit/service/mod.rs

@@ -104,6 +104,7 @@ impl Default for MountFlag {
     }
 }
 
+#[allow(dead_code)]
 #[derive(Default, Debug, Clone)]
 pub struct ServicePart {
     //生命周期相关
@@ -285,6 +286,7 @@ pub enum ServiceUnitAttr {
     MountFlags,
 }
 
+#[allow(dead_code)]
 impl ServicePart {
     pub fn set_attr(&'_ mut self, attr: &ServiceUnitAttr, val: &str) -> Result<(), ParseError> {
         match attr {