From 834a2f95a0af363bcfe5040b2c5994fd31793732 Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Fri, 25 Oct 2019 18:44:51 +0200 Subject: [PATCH] avoid some clippy warnings --- src/backup/crypt_config.rs | 3 +- src/backup/crypt_reader.rs | 26 ++++++++--------- src/backup/key_derivation.rs | 5 ++-- src/pxar/encoder.rs | 30 ++++++++------------ src/pxar/flags.rs | 52 +++++++++++++++++----------------- src/pxar/format_definition.rs | 1 + src/pxar/fuse.rs | 2 +- src/pxar/sequential_decoder.rs | 6 ++-- src/server/h2service.rs | 10 +++---- src/server/rest.rs | 2 +- src/server/upid.rs | 4 +-- src/tools/acl.rs | 8 +++--- src/tools/xattr.rs | 2 +- 13 files changed, 71 insertions(+), 80 deletions(-) diff --git a/src/backup/crypt_config.rs b/src/backup/crypt_config.rs index 2fec19bc..bb053ae8 100644 --- a/src/backup/crypt_config.rs +++ b/src/backup/crypt_config.rs @@ -67,8 +67,7 @@ impl CryptConfig { let mut hasher = openssl::sha::Sha256::new(); hasher.update(&self.id_key); hasher.update(data); - let digest = hasher.finish(); - digest + hasher.finish() } pub fn data_signer(&self) -> openssl::sign::Signer { diff --git a/src/backup/crypt_reader.rs b/src/backup/crypt_reader.rs index 5b77ec22..23bbd98a 100644 --- a/src/backup/crypt_reader.rs +++ b/src/backup/crypt_reader.rs @@ -67,25 +67,23 @@ impl Read for CryptReader { if count > buf.len() { buf.copy_from_slice(&outbuf[..buf.len()]); self.small_read_buf = outbuf[buf.len()..count].to_vec(); - return Ok(buf.len()); + Ok(buf.len()) } else { buf[..count].copy_from_slice(&outbuf[..count]); - return Ok(count); + Ok(count) } + } else if data.len() == 0 { // EOF + let rest = self.crypter.finalize(buf)?; + self.finalized = true; + Ok(rest) } else { - if data.len() == 0 { // EOF - let rest = self.crypter.finalize(buf)?; - self.finalized = true; - return Ok(rest) - } else { - let mut read_size = buf.len() - self.block_size; - if read_size > data.len() { - read_size = data.len(); - } - let count = self.crypter.update(&data[..read_size], buf)?; - self.reader.consume(read_size); - return Ok(count) + let mut read_size = buf.len() - self.block_size; + if read_size > data.len() { + read_size = data.len(); } + let count = self.crypter.update(&data[..read_size], buf)?; + self.reader.consume(read_size); + Ok(count) } } } diff --git a/src/backup/key_derivation.rs b/src/backup/key_derivation.rs index abe314b9..cb27ff35 100644 --- a/src/backup/key_derivation.rs +++ b/src/backup/key_derivation.rs @@ -176,16 +176,15 @@ pub fn load_and_decrtypt_key(path: &std::path::Path, passphrase: &dyn Fn() -> Re let cipher = openssl::symm::Cipher::aes_256_gcm(); - let decr_data = openssl::symm::decrypt_aead( + openssl::symm::decrypt_aead( cipher, &derived_key, Some(&iv), b"", //?? &enc_data, &tag, - ).map_err(|err| format_err!("Unable to decrypt key - {}", err))?; + ).map_err(|err| format_err!("Unable to decrypt key - {}", err))? - decr_data } else { raw_data }; diff --git a/src/pxar/encoder.rs b/src/pxar/encoder.rs index bffd6b22..0a44b40a 100644 --- a/src/pxar/encoder.rs +++ b/src/pxar/encoder.rs @@ -471,12 +471,12 @@ impl<'a, W: Write, C: BackupCatalogWriter> Encoder<'a, W, C> { let projid = fsxattr.fsx_projid as u64; if projid == 0 { - return Ok(None); + Ok(None) } else { - return Ok(Some(PxarQuotaProjID { projid })); + Ok(Some(PxarQuotaProjID { projid })) } } - _ => return Ok(None), + _ => Ok(None), } } @@ -680,12 +680,10 @@ impl<'a, W: Write, C: BackupCatalogWriter> Encoder<'a, W, C> { let include_children; if is_virtual_file_system(magic) { include_children = false; + } else if let Some(set) = &self.device_set { + include_children = set.contains(&dir_stat.st_dev); } else { - if let Some(set) = &self.device_set { - include_children = set.contains(&dir_stat.st_dev); - } else { - include_children = true; - } + include_children = true; } // Expand the exclude match pattern inherited from the parent by local entries, if present @@ -1036,12 +1034,10 @@ impl<'a, W: Write, C: BackupCatalogWriter> Encoder<'a, W, C> { let include_payload; if is_virtual_file_system(magic) { include_payload = false; + } else if let Some(ref set) = &self.device_set { + include_payload = set.contains(&stat.st_dev); } else { - if let Some(ref set) = &self.device_set { - include_payload = set.contains(&stat.st_dev); - } else { - include_payload = true; - } + include_payload = true; } if !include_payload { @@ -1178,12 +1174,10 @@ impl<'a, W: Write, C: BackupCatalogWriter> Encoder<'a, W, C> { let include_payload; if is_virtual_file_system(magic) { include_payload = false; + } else if let Some(set) = &self.device_set { + include_payload = set.contains(&stat.st_dev); } else { - if let Some(set) = &self.device_set { - include_payload = set.contains(&stat.st_dev); - } else { - include_payload = true; - } + include_payload = true; } if !include_payload { diff --git a/src/pxar/flags.rs b/src/pxar/flags.rs index a21000cf..81215b77 100644 --- a/src/pxar/flags.rs +++ b/src/pxar/flags.rs @@ -35,42 +35,42 @@ pub const WITH_FLAG_COMPR: u64 = 0x40000; /// Linux file attribute `NOCOW` pub const WITH_FLAG_NOCOW: u64 = 0x80000; /// Linux file attribute `NODUMP` -pub const WITH_FLAG_NODUMP: u64 = 0x100000; +pub const WITH_FLAG_NODUMP: u64 = 0x0010_0000; /// Linux file attribute `DIRSYNC` -pub const WITH_FLAG_DIRSYNC: u64 = 0x200000; +pub const WITH_FLAG_DIRSYNC: u64 = 0x0020_0000; /// Linux file attribute `IMMUTABLE` -pub const WITH_FLAG_IMMUTABLE: u64 = 0x400000; +pub const WITH_FLAG_IMMUTABLE: u64 = 0x0040_0000; /// Linux file attribute `SYNC` -pub const WITH_FLAG_SYNC: u64 = 0x800000; +pub const WITH_FLAG_SYNC: u64 = 0x0080_0000; /// Linux file attribute `NOCOMP` -pub const WITH_FLAG_NOCOMP: u64 = 0x1000000; +pub const WITH_FLAG_NOCOMP: u64 = 0x0100_0000; /// Linux file attribute `PROJINHERIT` -pub const WITH_FLAG_PROJINHERIT: u64 = 0x2000000; +pub const WITH_FLAG_PROJINHERIT: u64 = 0x0200_0000; /// Preserve BTRFS subvolume flag -pub const WITH_SUBVOLUME: u64 = 0x4000000; +pub const WITH_SUBVOLUME: u64 = 0x0400_0000; /// Preserve BTRFS read-only subvolume flag -pub const WITH_SUBVOLUME_RO: u64 = 0x8000000; +pub const WITH_SUBVOLUME_RO: u64 = 0x0800_0000; /// Preserve Extended Attribute metadata -pub const WITH_XATTRS: u64 = 0x10000000; +pub const WITH_XATTRS: u64 = 0x1000_0000; /// Preserve Access Control List metadata -pub const WITH_ACL: u64 = 0x20000000; +pub const WITH_ACL: u64 = 0x2000_0000; /// Preserve SELinux security context -pub const WITH_SELINUX: u64 = 0x40000000; +pub const WITH_SELINUX: u64 = 0x4000_0000; /// Preserve "security.capability" xattr -pub const WITH_FCAPS: u64 = 0x80000000; +pub const WITH_FCAPS: u64 = 0x8000_0000; /// Preserve XFS/ext4/ZFS project quota ID -pub const WITH_QUOTA_PROJID: u64 = 0x100000000; +pub const WITH_QUOTA_PROJID: u64 = 0x0001_0000_0000; /// Support ".pxarexclude" files -pub const EXCLUDE_FILE: u64 = 0x1000000000000000; +pub const EXCLUDE_FILE: u64 = 0x1000_0000_0000_0000; /// Exclude submounts -pub const EXCLUDE_SUBMOUNTS: u64 = 0x4000000000000000; +pub const EXCLUDE_SUBMOUNTS: u64 = 0x4000_0000_0000_0000; /// Exclude entries with chattr flag NODUMP -pub const EXCLUDE_NODUMP: u64 = 0x8000000000000000; +pub const EXCLUDE_NODUMP: u64 = 0x8000_0000_0000_0000; /// Definitions of typical feature flags for the *pxar* encoder/decoder. /// By this expensive syscalls for unsupported features are avoided. @@ -138,16 +138,16 @@ pub const DEFAULT: u64 = EXCLUDE_FILE; // form /usr/include/linux/fs.h -const FS_APPEND_FL: u32 = 0x00000020; -const FS_NOATIME_FL: u32 = 0x00000080; -const FS_COMPR_FL: u32 = 0x00000004; -const FS_NOCOW_FL: u32 = 0x00800000; -const FS_NODUMP_FL: u32 = 0x00000040; -const FS_DIRSYNC_FL: u32 = 0x00010000; -const FS_IMMUTABLE_FL: u32 = 0x00000010; -const FS_SYNC_FL: u32 = 0x00000008; -const FS_NOCOMP_FL: u32 = 0x00000400; -const FS_PROJINHERIT_FL: u32 = 0x20000000; +const FS_APPEND_FL: u32 = 0x0000_0020; +const FS_NOATIME_FL: u32 = 0x0000_0080; +const FS_COMPR_FL: u32 = 0x0000_0004; +const FS_NOCOW_FL: u32 = 0x0080_0000; +const FS_NODUMP_FL: u32 = 0x0000_0040; +const FS_DIRSYNC_FL: u32 = 0x0001_0000; +const FS_IMMUTABLE_FL: u32 = 0x0000_0010; +const FS_SYNC_FL: u32 = 0x0000_0008; +const FS_NOCOMP_FL: u32 = 0x0000_0400; +const FS_PROJINHERIT_FL: u32 = 0x2000_0000; static CHATTR_MAP: [(u64, u32); 10] = [ ( WITH_FLAG_APPEND, FS_APPEND_FL ), diff --git a/src/pxar/format_definition.rs b/src/pxar/format_definition.rs index 49ea7fd2..b80fc0c0 100644 --- a/src/pxar/format_definition.rs +++ b/src/pxar/format_definition.rs @@ -10,6 +10,7 @@ use endian_trait::Endian; use failure::{bail, Error}; use siphasher::sip::SipHasher24; + /// Header types identifying items stored in the archive pub const PXAR_ENTRY: u64 = 0x1396fabcea5bbb51; pub const PXAR_FILENAME: u64 = 0x6dbb6ebcb3161f0b; diff --git a/src/pxar/fuse.rs b/src/pxar/fuse.rs index ae7180b2..adcb3735 100644 --- a/src/pxar/fuse.rs +++ b/src/pxar/fuse.rs @@ -233,7 +233,7 @@ impl Session { Ok(Self { ptr: session_ptr, - verbose: verbose, + verbose, }) } diff --git a/src/pxar/sequential_decoder.rs b/src/pxar/sequential_decoder.rs index 4109ce3d..7a0cae07 100644 --- a/src/pxar/sequential_decoder.rs +++ b/src/pxar/sequential_decoder.rs @@ -1196,13 +1196,13 @@ fn nsec_to_update_timespec(mtime_nsec: u64) -> [libc::timespec; 2] { } fn mode_user_to_acl_permissions(mode: u64) -> u64 { - return (mode >> 6) & 7; + (mode >> 6) & 7 } fn mode_group_to_acl_permissions(mode: u64) -> u64 { - return (mode >> 3) & 7; + (mode >> 3) & 7 } fn mode_other_to_acl_permissions(mode: u64) -> u64 { - return mode & 7; + mode & 7 } diff --git a/src/server/h2service.rs b/src/server/h2service.rs index 52e41c3e..065102b9 100644 --- a/src/server/h2service.rs +++ b/src/server/h2service.rs @@ -54,15 +54,15 @@ impl H2Service { match self.router.find_method(&components, method, &mut uri_param) { MethodDefinition::None => { let err = http_err!(NOT_FOUND, "Path not found.".to_string()); - return Box::new(future::ok((formatter.format_error)(err))); + Box::new(future::ok((formatter.format_error)(err))) } MethodDefinition::Simple(api_method) => { - return crate::server::rest::handle_sync_api_request( - self.rpcenv.clone(), api_method, formatter, parts, body, uri_param); + crate::server::rest::handle_sync_api_request( + self.rpcenv.clone(), api_method, formatter, parts, body, uri_param) } MethodDefinition::Async(async_method) => { - return crate::server::rest::handle_async_api_request( - self.rpcenv.clone(), async_method, formatter, parts, body, uri_param); + crate::server::rest::handle_async_api_request( + self.rpcenv.clone(), async_method, formatter, parts, body, uri_param) } } } diff --git a/src/server/rest.rs b/src/server/rest.rs index efa6e07a..af3b74b2 100644 --- a/src/server/rest.rs +++ b/src/server/rest.rs @@ -484,7 +484,7 @@ fn handle_static_file_download(filename: PathBuf) -> BoxFut { } }); - return Box::new(response); + Box::new(response) } fn extract_auth_data(headers: &http::HeaderMap) -> (Option, Option) { diff --git a/src/server/upid.rs b/src/server/upid.rs index af8bd282..e4ff16f3 100644 --- a/src/server/upid.rs +++ b/src/server/upid.rs @@ -95,7 +95,7 @@ impl std::str::FromStr for UPID { if let Some(cap) = REGEX.captures(s) { - return Ok(UPID { + Ok(UPID { pid: i32::from_str_radix(&cap["pid"], 16).unwrap(), pstart: u64::from_str_radix(&cap["pstart"], 16).unwrap(), starttime: i64::from_str_radix(&cap["starttime"], 16).unwrap(), @@ -104,7 +104,7 @@ impl std::str::FromStr for UPID { worker_id: if cap["wid"].is_empty() { None } else { Some(cap["wid"].to_string()) }, username: cap["username"].to_string(), node: cap["node"].to_string(), - }); + }) } else { bail!("unable to parse UPID '{}'", s); } diff --git a/src/tools/acl.rs b/src/tools/acl.rs index 1add0966..09bf16db 100644 --- a/src/tools/acl.rs +++ b/src/tools/acl.rs @@ -79,7 +79,7 @@ impl ACL { return Err(Errno::last()); } - Ok(ACL { ptr: ptr }) + Ok(ACL { ptr }) } pub fn get_file>(path: P, acl_type: ACLType) -> Result { @@ -89,7 +89,7 @@ impl ACL { return Err(Errno::last()); } - Ok(ACL { ptr: ptr }) + Ok(ACL { ptr }) } pub fn set_file>(&self, path: P, acl_type: ACLType) -> Result<(), nix::errno::Errno> { @@ -108,7 +108,7 @@ impl ACL { return Err(Errno::last()); } - Ok(ACL { ptr: ptr }) + Ok(ACL { ptr }) } pub fn create_entry<'a>(&'a mut self) -> Result, nix::errno::Errno> { @@ -119,7 +119,7 @@ impl ACL { } Ok(ACLEntry { - ptr: ptr, + ptr, _phantom: PhantomData, }) } diff --git a/src/tools/xattr.rs b/src/tools/xattr.rs index 6f49ad65..006010b2 100644 --- a/src/tools/xattr.rs +++ b/src/tools/xattr.rs @@ -155,7 +155,7 @@ mod tests { } let invalid_name_length = PxarXAttr { - name: name, + name, value: b"err".to_vec(), };