diff options
| author | 魏曹先生 <1992414357@qq.com> | 2025-09-25 14:23:55 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2025-09-25 14:23:55 +0800 |
| commit | e2e29c3934e40cfd4fde6f1b5e7517810c3bf1cd (patch) | |
| tree | 2629abac480a4ca697c8dec09e7f79f690be3b8b /crates | |
| parent | 300b0eeb68618a2b66469e83b79384a2d612c05d (diff) | |
Fixed by Clippy
Diffstat (limited to 'crates')
| -rw-r--r-- | crates/utils/cfg_file/src/config.rs | 2 | ||||
| -rw-r--r-- | crates/utils/string_proc/src/string_processer.rs | 5 | ||||
| -rw-r--r-- | crates/utils/tcp_connection/src/instance.rs | 24 | ||||
| -rw-r--r-- | crates/utils/tcp_connection/src/target_connection.rs | 6 | ||||
| -rw-r--r-- | crates/vcs/src/workspace/local.rs | 6 | ||||
| -rw-r--r-- | crates/vcs/src/workspace/vault/member.rs | 16 | ||||
| -rw-r--r-- | crates/vcs/src/workspace/vault/virtual_file.rs | 11 |
7 files changed, 31 insertions, 39 deletions
diff --git a/crates/utils/cfg_file/src/config.rs b/crates/utils/cfg_file/src/config.rs index 75c598b..0211e75 100644 --- a/crates/utils/cfg_file/src/config.rs +++ b/crates/utils/cfg_file/src/config.rs @@ -56,7 +56,7 @@ pub trait ConfigFile: Serialize + for<'a> Deserialize<'a> + Default { let file_path = cwd.join(path); // Check if file exists - if !fs::metadata(&file_path).await.is_ok() { + if fs::metadata(&file_path).await.is_err() { return Ok(Self::DataType::default()); } diff --git a/crates/utils/string_proc/src/string_processer.rs b/crates/utils/string_proc/src/string_processer.rs index 6ad8768..8b51c12 100644 --- a/crates/utils/string_proc/src/string_processer.rs +++ b/crates/utils/string_proc/src/string_processer.rs @@ -45,11 +45,10 @@ impl StringProcesser { while let Some(c) = chars.next() { processed.push(c); - if let Some(&next) = chars.peek() { - if c.is_lowercase() && next.is_uppercase() { + if let Some(&next) = chars.peek() + && c.is_lowercase() && next.is_uppercase() { processed.push(' '); } - } } processed diff --git a/crates/utils/tcp_connection/src/instance.rs b/crates/utils/tcp_connection/src/instance.rs index 8bcb718..217b10a 100644 --- a/crates/utils/tcp_connection/src/instance.rs +++ b/crates/utils/tcp_connection/src/instance.rs @@ -318,11 +318,10 @@ impl ConnectionInstance { let crc_instance = crc::Crc::<u32>::new(&crc::CRC_32_ISO_HDLC); // Make sure parent directory exists - if let Some(parent) = path.parent() { - if !parent.exists() { + if let Some(parent) = path.parent() + && !parent.exists() { tokio::fs::create_dir_all(parent).await?; } - } // Read file header (version + size + crc) let mut version_buf = [0u8; 8]; @@ -398,8 +397,8 @@ impl ConnectionInstance { writer.flush().await?; // Validate CRC if enabled - if self.config.enable_crc_validation { - if let Some(crc_calculator) = crc_calculator { + if self.config.enable_crc_validation + && let Some(crc_calculator) = crc_calculator { let actual_crc = crc_calculator.finalize(); if actual_crc != expected_crc && expected_crc != 0 { return Err(TcpTargetError::File(format!( @@ -408,7 +407,6 @@ impl ConnectionInstance { ))); } } - } // Final flush and sync writer.flush().await?; @@ -577,25 +575,23 @@ fn parse_ed25519_public_key(pem: &str) -> [u8; 32] { // Robust parsing for Ed25519 public key using pem crate let mut key_bytes = [0u8; 32]; - if let Ok(pem_data) = pem::parse(pem) { - if pem_data.tag() == "PUBLIC KEY" && pem_data.contents().len() >= 32 { + if let Ok(pem_data) = pem::parse(pem) + && pem_data.tag() == "PUBLIC KEY" && pem_data.contents().len() >= 32 { let contents = pem_data.contents(); key_bytes.copy_from_slice(&contents[contents.len() - 32..]); } - } key_bytes } /// Parse Ed25519 private key from PEM format fn parse_ed25519_private_key(pem: &str) -> Result<SigningKey, TcpTargetError> { - if let Ok(pem_data) = pem::parse(pem) { - if pem_data.tag() == "PRIVATE KEY" && pem_data.contents().len() >= 32 { + if let Ok(pem_data) = pem::parse(pem) + && pem_data.tag() == "PRIVATE KEY" && pem_data.contents().len() >= 32 { let contents = pem_data.contents(); let mut seed = [0u8; 32]; seed.copy_from_slice(&contents[contents.len() - 32..]); return Ok(SigningKey::from_bytes(&seed)); } - } Err(TcpTargetError::Crypto( "Invalid Ed25519 private key format".to_string(), )) @@ -666,7 +662,7 @@ fn sign_with_dsa( if algorithm_ptr == ecdsa_p256_ptr { let key_pair = EcdsaKeyPair::from_pkcs8( ECDSA_P256_SHA256_ASN1_SIGNING, - &key_bytes, + key_bytes, &SystemRandom::new(), ) .map_err(|e| { @@ -681,7 +677,7 @@ fn sign_with_dsa( } else if algorithm_ptr == ecdsa_p384_ptr { let key_pair = EcdsaKeyPair::from_pkcs8( ECDSA_P384_SHA384_ASN1_SIGNING, - &key_bytes, + key_bytes, &SystemRandom::new(), ) .map_err(|e| { diff --git a/crates/utils/tcp_connection/src/target_connection.rs b/crates/utils/tcp_connection/src/target_connection.rs index b03093c..87fd1ab 100644 --- a/crates/utils/tcp_connection/src/target_connection.rs +++ b/crates/utils/tcp_connection/src/target_connection.rs @@ -24,7 +24,7 @@ where let Ok(socket) = TcpSocket::new_v4() else { return Err(TcpTargetError::from("Create tcp socket failed!")); }; - let stream = match socket.connect(addr.clone()).await { + let stream = match socket.connect(addr).await { Ok(stream) => stream, Err(e) => { let err = format!("Connect to `{}` failed: {}", addr, e); @@ -40,7 +40,7 @@ where /// This function initiates a connection to the server address specified in the target configuration. pub async fn listen(&self) -> Result<(), TcpTargetError> { let addr = self.get_addr(); - let listener = match TcpListener::bind(addr.clone()).await { + let listener = match TcpListener::bind(addr).await { Ok(listener) => listener, Err(_) => { let err = format!("Bind to `{}` failed", addr); @@ -49,7 +49,7 @@ where }; let cfg: ServerTargetConfig = match self.get_server_cfg() { - Some(cfg) => cfg.clone(), + Some(cfg) => *cfg, None => ServerTargetConfig::default(), }; diff --git a/crates/vcs/src/workspace/local.rs b/crates/vcs/src/workspace/local.rs index 0119952..6beb842 100644 --- a/crates/vcs/src/workspace/local.rs +++ b/crates/vcs/src/workspace/local.rs @@ -57,8 +57,7 @@ impl LocalWorkspace { LocalConfig::write_to(&config, local_path.join(CLIENT_FILE_WORKSPACE)).await?; // 2. Setup README.md - let readme_content = format!( - "\ + let readme_content = "\ # JustEnoughVCS Local Workspace This directory is a **Local Workspace** managed by `JustEnoughVCS`. All files and subdirectories within this scope can be version-controlled using the `JustEnoughVCS` CLI or GUI tools, with the following exceptions: @@ -89,8 +88,7 @@ Without these credentials, the server will reject all access requests. ------ *Thank you for using JustEnoughVCS!* -" - ) +".to_string() .trim() .to_string(); fs::write(local_path.join(CLIENT_FILE_README), readme_content).await?; diff --git a/crates/vcs/src/workspace/vault/member.rs b/crates/vcs/src/workspace/vault/member.rs index 793ba2a..2d00081 100644 --- a/crates/vcs/src/workspace/vault/member.rs +++ b/crates/vcs/src/workspace/vault/member.rs @@ -31,7 +31,7 @@ impl Vault { /// Update member info pub async fn update_member(&self, member: Member) -> Result<(), std::io::Error> { // Ensure member exist - if let Some(_) = self.member_cfg(&member.id()) { + if self.member_cfg(&member.id()).is_some() { let member_cfg_path = self.member_cfg_path(&member.id()); Member::write_to(&member, member_cfg_path).await?; return Ok(()); @@ -43,7 +43,7 @@ impl Vault { /// Register a member to vault pub async fn register_member_to_vault(&self, member: Member) -> Result<(), std::io::Error> { // Ensure member not exist - if let Some(_) = self.member_cfg(&member.id()) { + if self.member_cfg(&member.id()).is_some() { return Err(Error::new( ErrorKind::DirectoryNotEmpty, format!("Member `{}` already registered!", member.id()), @@ -89,17 +89,17 @@ impl Vault { /// Get the member's configuration file path, but do not check if the file exists pub fn member_cfg_path(&self, id: &MemberId) -> PathBuf { - let path = self + + self .vault_path - .join(SERVER_FILE_MEMBER_INFO.replace(ID_PARAM, id.to_string().as_str())); - path + .join(SERVER_FILE_MEMBER_INFO.replace(ID_PARAM, id.to_string().as_str())) } /// Get the member's public key file path, but do not check if the file exists pub fn member_key_path(&self, id: &MemberId) -> PathBuf { - let path = self + + self .vault_path - .join(SERVER_FILE_MEMBER_PUB.replace(ID_PARAM, id.to_string().as_str())); - path + .join(SERVER_FILE_MEMBER_PUB.replace(ID_PARAM, id.to_string().as_str())) } } diff --git a/crates/vcs/src/workspace/vault/virtual_file.rs b/crates/vcs/src/workspace/vault/virtual_file.rs index 6e8c28d..95f3d8c 100644 --- a/crates/vcs/src/workspace/vault/virtual_file.rs +++ b/crates/vcs/src/workspace/vault/virtual_file.rs @@ -236,11 +236,10 @@ impl Vault { VirtualFileMeta::write_to(&meta, self.virtual_file_meta_path(&new_id)).await?; // Move temp file to virtual file directory - if let Some(parent) = move_path.parent() { - if !parent.exists() { + if let Some(parent) = move_path.parent() + && !parent.exists() { fs::create_dir_all(parent).await?; } - } fs::rename(receive_path, move_path).await?; Ok(new_id) @@ -251,7 +250,7 @@ impl Vault { fs::remove_file(receive_path).await?; } - Err(Error::new(ErrorKind::Other, e)) + Err(Error::other(e)) } } } @@ -312,7 +311,7 @@ impl Vault { VirtualFileMeta::write_to(&meta, self.virtual_file_meta_path(virtual_file_id)) .await?; - return Ok(()); + Ok(()) } Err(e) => { // Read failed, remove temp file. @@ -320,7 +319,7 @@ impl Vault { fs::remove_file(receive_path).await?; } - return Err(Error::new(ErrorKind::Other, e)); + Err(Error::other(e)) } } } |
