diff --git a/src/api2.rs b/src/api2.rs index c44fa616..00514fbe 100644 --- a/src/api2.rs +++ b/src/api2.rs @@ -15,7 +15,7 @@ pub fn router() -> Router { let nodes = Router::new() .match_all("node", node::router()); - let route = Router::new() + Router::new() .subdir("access", access::router()) .subdir("admin", admin::router()) .subdir("backup", backup::router()) @@ -24,7 +24,5 @@ pub fn router() -> Router { .subdir("nodes", nodes) .subdir("subscription", subscription::router()) .subdir("version", version::router()) - .list_subdirs(); - - route + .list_subdirs() } diff --git a/src/api2/access.rs b/src/api2/access.rs index 129997be..2907747f 100644 --- a/src/api2/access.rs +++ b/src/api2/access.rs @@ -52,23 +52,22 @@ fn create_ticket( log::info!("successful auth for user '{}'", username); - return Ok(json!({ + Ok(json!({ "username": username, "ticket": ticket, "CSRFPreventionToken": token, - })); + })) } Err(err) => { let client_ip = "unknown"; // $rpcenv->get_client_ip() || ''; log::error!("authentication failure; rhost={} user={} msg={}", client_ip, username, err.to_string()); - return Err(http_err!(UNAUTHORIZED, "permission check failed.".into())); + Err(http_err!(UNAUTHORIZED, "permission check failed.".into())) } } } pub fn router() -> Router { - - let route = Router::new() + Router::new() .subdir( "ticket", Router::new() @@ -93,7 +92,5 @@ pub fn router() -> Router { ).protected(true) ) ) - .list_subdirs(); - - route + .list_subdirs() } diff --git a/src/api2/admin.rs b/src/api2/admin.rs index 6807dfce..e2bf265d 100644 --- a/src/api2/admin.rs +++ b/src/api2/admin.rs @@ -3,10 +3,7 @@ use crate::api_schema::router::*; pub mod datastore; pub fn router() -> Router { - - let route = Router::new() + Router::new() .subdir("datastore", datastore::router()) - .list_subdirs(); - - route + .list_subdirs() } diff --git a/src/api2/admin/datastore.rs b/src/api2/admin/datastore.rs index cf76cb15..d4023c0d 100644 --- a/src/api2/admin/datastore.rs +++ b/src/api2/admin/datastore.rs @@ -654,15 +654,9 @@ pub fn router() -> Router { ) .list_subdirs(); - - - let route = Router::new() + Router::new() .get(ApiMethod::new( get_datastore_list, ObjectSchema::new("Directory index."))) - .match_all("store", datastore_info); - - - - route + .match_all("store", datastore_info) } diff --git a/src/api2/backup.rs b/src/api2/backup.rs index 746236b5..9f46e9de 100644 --- a/src/api2/backup.rs +++ b/src/api2/backup.rs @@ -167,8 +167,7 @@ lazy_static!{ } pub fn backup_api() -> Router { - - let router = Router::new() + Router::new() .subdir( "blob", Router::new() .upload(api_method_upload_blob()) @@ -214,9 +213,7 @@ pub fn backup_api() -> Router { "speedtest", Router::new() .upload(api_method_upload_speedtest()) ) - .list_subdirs(); - - router + .list_subdirs() } pub fn api_method_create_dynamic_index() -> ApiMethod { diff --git a/src/api2/config.rs b/src/api2/config.rs index 464e6496..699c5f35 100644 --- a/src/api2/config.rs +++ b/src/api2/config.rs @@ -7,11 +7,7 @@ use crate::api_schema::router::*; pub mod datastore; pub fn router() -> Router { - - let route = Router::new() + Router::new() .subdir("datastore", datastore::router()) - .list_subdirs(); - - - route + .list_subdirs() } diff --git a/src/api2/config/datastore.rs b/src/api2/config/datastore.rs index 37a29368..7a27d3e7 100644 --- a/src/api2/config/datastore.rs +++ b/src/api2/config/datastore.rs @@ -97,12 +97,8 @@ fn delete_datastore( } pub fn router() -> Router { - - let route = Router::new() + Router::new() .get(get()) .post(post()) - .delete(delete()); - - - route + .delete(delete()) } diff --git a/src/api2/node.rs b/src/api2/node.rs index 2334437d..1ae64c72 100644 --- a/src/api2/node.rs +++ b/src/api2/node.rs @@ -8,15 +8,12 @@ mod syslog; mod services; pub fn router() -> Router { - - let route = Router::new() + Router::new() .subdir("dns", dns::router()) .subdir("network", network::router()) .subdir("services", services::router()) .subdir("syslog", syslog::router()) .subdir("tasks", tasks::router()) .subdir("time", time::router()) - .list_subdirs(); - - route + .list_subdirs() } diff --git a/src/api2/node/dns.rs b/src/api2/node/dns.rs index af8ec643..2b33a3d9 100644 --- a/src/api2/node/dns.rs +++ b/src/api2/node/dns.rs @@ -108,8 +108,7 @@ fn get_dns( } pub fn router() -> Router { - - let route = Router::new() + Router::new() .get( ApiMethod::new( get_dns, @@ -135,7 +134,5 @@ pub fn router() -> Router { .optional("dns3", THIRD_DNS_SERVER_SCHEMA.clone()) .optional("digest", PVE_CONFIG_DIGEST_SCHEMA.clone()) ).protected(true) - ); - - route + ) } diff --git a/src/api2/node/network.rs b/src/api2/node/network.rs index c390e216..6a2db3dd 100644 --- a/src/api2/node/network.rs +++ b/src/api2/node/network.rs @@ -17,13 +17,10 @@ fn get_network_config( } pub fn router() -> Router { - - let route = Router::new() + Router::new() .get(ApiMethod::new( get_network_config, ObjectSchema::new("Read network configuration.") .required("node", NODE_SCHEMA.clone()) - )); - - route + )) } diff --git a/src/api2/node/services.rs b/src/api2/node/services.rs index 9a1ccfe3..330ff21f 100644 --- a/src/api2/node/services.rs +++ b/src/api2/node/services.rs @@ -140,10 +140,8 @@ fn run_service_command(service: &str, cmd: &str) -> Result { _ => bail!("unknown service command '{}'", cmd), } - if service == "proxmox-backup" { - if cmd != "restart" { - bail!("invalid service cmd '{} {}'", service, cmd); - } + if service == "proxmox-backup" && cmd != "restart" { + bail!("invalid service cmd '{} {}'", service, cmd); } let real_service_name = real_service_name(service); @@ -285,7 +283,7 @@ pub fn router() -> Router { ) .list_subdirs(); - let route = Router::new() + Router::new() .get( ApiMethod::new( list_services, @@ -303,7 +301,5 @@ pub fn router() -> Router { ) ) ) - .match_all("service", service_api); - - route + .match_all("service", service_api) } diff --git a/src/api2/node/syslog.rs b/src/api2/node/syslog.rs index 33e64140..cb30f7ee 100644 --- a/src/api2/node/syslog.rs +++ b/src/api2/node/syslog.rs @@ -97,8 +97,7 @@ lazy_static! { } pub fn router() -> Router { - - let route = Router::new() + Router::new() .get( ApiMethod::new( get_syslog, @@ -134,7 +133,5 @@ pub fn router() -> Router { .required("n", IntegerSchema::new("Line number.")) .required("t", StringSchema::new("Line text.")) ).protected(true) - ); - - route + ) } diff --git a/src/api2/node/tasks.rs b/src/api2/node/tasks.rs index 450547d3..64f73c40 100644 --- a/src/api2/node/tasks.rs +++ b/src/api2/node/tasks.rs @@ -218,7 +218,7 @@ pub fn router() -> Router { .list_subdirs(); - let route = Router::new() + Router::new() .get(ApiMethod::new( list_tasks, ObjectSchema::new("List tasks.") @@ -245,7 +245,5 @@ pub fn router() -> Router { ) ) ) - .match_all("upid", upid_api); - - route + .match_all("upid", upid_api) } diff --git a/src/api2/node/time.rs b/src/api2/node/time.rs index f1811cdb..2940d08b 100644 --- a/src/api2/node/time.rs +++ b/src/api2/node/time.rs @@ -81,7 +81,7 @@ fn set_timezone( } pub fn router() -> Router { - let route = Router::new() + Router::new() .get( ApiMethod::new( get_time, @@ -91,9 +91,9 @@ pub fn router() -> Router { ObjectSchema::new("Returns server time and timezone.") .required("timezone", StringSchema::new("Time zone")) .required("time", IntegerSchema::new("Seconds since 1970-01-01 00:00:00 UTC.") - .minimum(1297163644)) + .minimum(1_297_163_644)) .required("localtime", IntegerSchema::new("Seconds since 1970-01-01 00:00:00 UTC. (local time)") - .minimum(1297163644)) + .minimum(1_297_163_644)) ) ) .put( @@ -104,7 +104,5 @@ pub fn router() -> Router { .required("timezone", StringSchema::new( "Time zone. The file '/usr/share/zoneinfo/zone.tab' contains the list of valid names.")) ).protected(true).reload_timezone(true) - ); - - route + ) } diff --git a/src/api2/reader.rs b/src/api2/reader.rs index 8edd3f3b..6aa5504c 100644 --- a/src/api2/reader.rs +++ b/src/api2/reader.rs @@ -35,7 +35,7 @@ pub fn api_method_upgrade_backup() -> ApiAsyncMethod { .format(Arc::new(ApiStringFormat::Enum(&["vm", "ct", "host"])))) .required("backup-id", StringSchema::new("Backup ID.")) .required("backup-time", IntegerSchema::new("Backup time (Unix epoch.)") - .minimum(1547797308)) + .minimum(1_547_797_308)) .optional("debug", BooleanSchema::new("Enable verbose debug logging.")) ) } @@ -139,8 +139,7 @@ lazy_static!{ } pub fn reader_api() -> Router { - - let router = Router::new() + Router::new() .subdir( "chunk", Router::new() .download(api_method_download_chunk()) @@ -152,9 +151,7 @@ pub fn reader_api() -> Router { .subdir( "speedtest", Router::new() .download(api_method_speedtest()) - ); - - router + ) } pub fn api_method_download_file() -> ApiAsyncMethod { diff --git a/src/api2/subscription.rs b/src/api2/subscription.rs index 058c692d..b0a2e97f 100644 --- a/src/api2/subscription.rs +++ b/src/api2/subscription.rs @@ -22,11 +22,8 @@ fn get_subscription( } pub fn router() -> Router { - - let route = Router::new() + Router::new() .get(ApiMethod::new( get_subscription, - ObjectSchema::new("Read subscription info."))); - - route + ObjectSchema::new("Read subscription info."))) } diff --git a/src/api2/types.rs b/src/api2/types.rs index a0e40eed..731c7554 100644 --- a/src/api2/types.rs +++ b/src/api2/types.rs @@ -79,7 +79,7 @@ lazy_static!{ pub static ref BACKUP_TIME_SCHEMA: Arc = IntegerSchema::new("Backup time (Unix epoch.)") - .minimum(1547797308) + .minimum(1_547_797_308) .into(); } diff --git a/src/api2/version.rs b/src/api2/version.rs index a000fe37..f7e20844 100644 --- a/src/api2/version.rs +++ b/src/api2/version.rs @@ -4,14 +4,14 @@ use crate::api_schema::*; use crate::api_schema::router::*; use serde_json::{json, Value}; -pub const PROXMOX_PKG_VERSION: &'static str = +pub const PROXMOX_PKG_VERSION: &str = concat!( env!("CARGO_PKG_VERSION_MAJOR"), ".", env!("CARGO_PKG_VERSION_MINOR"), ); -pub const PROXMOX_PKG_RELEASE: &'static str = env!("CARGO_PKG_VERSION_PATCH"); -pub const PROXMOX_PKG_REPOID: &'static str = env!("CARGO_PKG_REPOSITORY"); +pub const PROXMOX_PKG_RELEASE: &str = env!("CARGO_PKG_VERSION_PATCH"); +pub const PROXMOX_PKG_REPOID: &str = env!("CARGO_PKG_REPOSITORY"); fn get_version( _param: Value, @@ -27,11 +27,8 @@ fn get_version( } pub fn router() -> Router { - - let route = Router::new() + Router::new() .get(ApiMethod::new( get_version, - ObjectSchema::new("Proxmox Backup Server API version."))); - - route + ObjectSchema::new("Proxmox Backup Server API version."))) } diff --git a/src/api_schema/format.rs b/src/api_schema/format.rs index 2af0be85..d53ddaec 100644 --- a/src/api_schema/format.rs +++ b/src/api_schema/format.rs @@ -38,9 +38,9 @@ pub fn wrap_text(initial_indent: &str, subsequent_indent: &str, text: &str, colu text.split("\n\n") .map(|p| p.trim()) - .filter(|p| { p.len() != 0 }) + .filter(|p| !p.is_empty()) .fold(String::new(), |mut acc, p| { - if acc.len() == 0 { + if acc.is_empty() { acc.push_str(&wrapper1.wrap(p).concat()); } else { acc.push_str(&wrapper2.wrap(p).concat()); @@ -142,11 +142,11 @@ fn dump_api_parameters(param: &ObjectSchema) -> String { let properties = ¶m.properties; - let mut prop_names: Vec<&str> = properties.keys().map(|v| *v).collect(); + let mut prop_names: Vec<&str> = properties.keys().copied().collect(); prop_names.sort(); - let mut required_list: Vec = vec![]; - let mut optional_list: Vec = vec![]; + let mut required_list: Vec = Vec::new(); + let mut optional_list: Vec = Vec::new(); for prop in prop_names { let (optional, schema) = properties.get(prop).unwrap(); @@ -161,7 +161,7 @@ fn dump_api_parameters(param: &ObjectSchema) -> String { } } - if required_list.len() > 0 { + if !required_list.is_empty() { res.push_str("\n*Required properties:*\n\n"); @@ -172,7 +172,7 @@ fn dump_api_parameters(param: &ObjectSchema) -> String { } - if optional_list.len() > 0 { + if !optional_list.is_empty() { res.push_str("\n*Optional properties:*\n\n"); diff --git a/src/api_schema/registry.rs b/src/api_schema/registry.rs index 451d7c96..ae4c3875 100644 --- a/src/api_schema/registry.rs +++ b/src/api_schema/registry.rs @@ -4,6 +4,7 @@ use failure::*; use std::collections::HashMap; use std::sync::Arc; +#[derive(Default)] pub struct Registry { formats: HashMap<&'static str, Arc>, options: HashMap<&'static str, Arc>, diff --git a/src/api_schema/router.rs b/src/api_schema/router.rs index bb44a2a3..c449de0b 100644 --- a/src/api_schema/router.rs +++ b/src/api_schema/router.rs @@ -284,7 +284,7 @@ impl Router { pub fn find_route(&self, components: &[&str], uri_param: &mut HashMap) -> Option<&Router> { - if components.len() == 0 { return Some(self); }; + if components.is_empty() { return Some(self); }; let (dir, rest) = (components[0], &components[1..]); @@ -325,3 +325,9 @@ impl Router { &MethodDefinition::None } } + +impl Default for Router { + fn default() -> Self { + Self::new() + } +} diff --git a/src/api_schema/schema.rs b/src/api_schema/schema.rs index a7875575..5bf9dd66 100644 --- a/src/api_schema/schema.rs +++ b/src/api_schema/schema.rs @@ -6,7 +6,7 @@ use regex::Regex; use std::fmt; use std::sync::Arc; -#[derive(Debug, Fail)] +#[derive(Default, Debug, Fail)] pub struct ParameterError { error_list: Vec, } @@ -22,7 +22,7 @@ pub struct ParameterError { impl ParameterError { pub fn new() -> Self { - Self { error_list: vec![] } + Self { error_list: Vec::new() } } pub fn push(&mut self, value: Error) { @@ -32,6 +32,10 @@ impl ParameterError { pub fn len(&self) -> usize { self.error_list.len() } + + pub fn is_empty(&self) -> bool { + self.len() == 0 + } } impl fmt::Display for ParameterError { @@ -39,7 +43,7 @@ impl fmt::Display for ParameterError { let mut msg = String::new(); - if self.len() > 0 { + if !self.is_empty() { msg.push_str("parameter verification errors\n\n"); } @@ -470,7 +474,7 @@ pub fn parse_simple_value(value_str: &str, schema: &Schema) -> Result, schema: &ObjectSchema, test_required: bool) -> Result { +pub fn parse_parameter_strings(data: &[(String, String)], schema: &ObjectSchema, test_required: bool) -> Result { let mut params = json!({}); @@ -530,13 +534,13 @@ pub fn parse_parameter_strings(data: &Vec<(String, String)>, schema: &ObjectSche if test_required && errors.len() == 0 { for (name, (optional, _prop_schema)) in properties { - if *optional == false && params[name] == Value::Null { + if !(*optional) && params[name] == Value::Null { errors.push(format_err!("parameter '{}': parameter is missing and it is not optional.", name)); } } } - if errors.len() > 0 { + if !errors.is_empty() { Err(errors) } else { Ok(params) @@ -640,7 +644,7 @@ pub fn verify_json_object(data: &Value, schema: &ObjectSchema) -> Result<(), Err } for (name, (optional, _prop_schema)) in properties { - if *optional == false && data[name] == Value::Null { + if !(*optional) && data[name] == Value::Null { bail!("property '{}': property is missing and it is not optional.", name); } } diff --git a/src/backup/catalog_blob.rs b/src/backup/catalog_blob.rs index 88c4d4e5..695261a0 100644 --- a/src/backup/catalog_blob.rs +++ b/src/backup/catalog_blob.rs @@ -174,11 +174,10 @@ impl CatalogBlobReader { let etype = match self.next_byte() { Ok(v) => v, Err(err) => { - if err.kind() == std::io::ErrorKind::UnexpectedEof { - if self.dir_stack.len() == 0 { - break; - } + if err.kind() == std::io::ErrorKind::UnexpectedEof && self.dir_stack.len() == 0 { + break; } + return Err(err.into()); } }; diff --git a/src/backup/chunk_store.rs b/src/backup/chunk_store.rs index 9fcf3de8..92726c55 100644 --- a/src/backup/chunk_store.rs +++ b/src/backup/chunk_store.rs @@ -60,7 +60,7 @@ fn digest_to_prefix(digest: &[u8]) -> PathBuf { let mut buf = Vec::::with_capacity(2+1+2+1); - const HEX_CHARS: &'static [u8; 16] = b"0123456789abcdef"; + const HEX_CHARS: &[u8; 16] = b"0123456789abcdef"; buf.push(HEX_CHARS[(digest[0] as usize) >> 4]); buf.push(HEX_CHARS[(digest[0] as usize) &0xf]); diff --git a/src/backup/data_blob.rs b/src/backup/data_blob.rs index 518aff2d..925e9ce6 100644 --- a/src/backup/data_blob.rs +++ b/src/backup/data_blob.rs @@ -173,11 +173,11 @@ impl DataBlob { if magic == &UNCOMPRESSED_BLOB_MAGIC_1_0 { let data_start = std::mem::size_of::(); - return Ok(self.raw_data[data_start..].to_vec()); + Ok(self.raw_data[data_start..].to_vec()) } else if magic == &COMPRESSED_BLOB_MAGIC_1_0 { let data_start = std::mem::size_of::(); let data = zstd::block::decompress(&self.raw_data[data_start..], MAX_BLOB_SIZE)?; - return Ok(data); + Ok(data) } else if magic == &ENCR_COMPR_BLOB_MAGIC_1_0 || magic == &ENCRYPTED_BLOB_MAGIC_1_0 { let header_len = std::mem::size_of::(); let head = unsafe { @@ -190,7 +190,7 @@ impl DataBlob { } else { config.decode_uncompressed_chunk(&self.raw_data[header_len..], &head.iv, &head.tag)? }; - return Ok(data); + Ok(data) } else { bail!("unable to decrypt blob - missing CryptConfig"); } @@ -212,9 +212,9 @@ impl DataBlob { if magic == &AUTH_COMPR_BLOB_MAGIC_1_0 { let data = zstd::block::decompress(&self.raw_data[data_start..], 16*1024*1024)?; - return Ok(data); + Ok(data) } else { - return Ok(self.raw_data[data_start..].to_vec()); + Ok(self.raw_data[data_start..].to_vec()) } } else { bail!("Invalid blob magic number."); @@ -260,7 +260,7 @@ impl DataBlob { let mut blob = DataBlob { raw_data }; blob.set_crc(blob.compute_crc()); - return Ok(blob); + Ok(blob) } /// Load blob from ``reader`` diff --git a/src/backup/data_blob_writer.rs b/src/backup/data_blob_writer.rs index 86aa9d65..e843cd06 100644 --- a/src/backup/data_blob_writer.rs +++ b/src/backup/data_blob_writer.rs @@ -114,7 +114,7 @@ impl DataBlobWriter { writer.write_le_value(head)?; } - return Ok(writer) + Ok(writer) } BlobWriterState::Compressed { compr } => { let csum_writer = compr.finish()?; @@ -127,7 +127,7 @@ impl DataBlobWriter { writer.write_le_value(head)?; } - return Ok(writer) + Ok(writer) } BlobWriterState::Signed { csum_writer } => { let (mut writer, crc, tag) = csum_writer.finish()?; @@ -142,7 +142,7 @@ impl DataBlobWriter { writer.write_le_value(head)?; } - return Ok(writer) + Ok(writer) } BlobWriterState::SignedCompressed { compr } => { let csum_writer = compr.finish()?; @@ -158,7 +158,7 @@ impl DataBlobWriter { writer.write_le_value(head)?; } - return Ok(writer) + Ok(writer) } BlobWriterState::Encrypted { crypt_writer } => { let (csum_writer, iv, tag) = crypt_writer.finish()?; @@ -172,7 +172,7 @@ impl DataBlobWriter { unsafe { writer.write_le_value(head)?; } - return Ok(writer) + Ok(writer) } BlobWriterState::EncryptedCompressed { compr } => { let crypt_writer = compr.finish()?; @@ -187,7 +187,7 @@ impl DataBlobWriter { unsafe { writer.write_le_value(head)?; } - return Ok(writer) + Ok(writer) } } } diff --git a/src/backup/dynamic_index.rs b/src/backup/dynamic_index.rs index ddb09f9a..eb780c7a 100644 --- a/src/backup/dynamic_index.rs +++ b/src/backup/dynamic_index.rs @@ -227,9 +227,9 @@ impl DynamicIndexReader { let middle_end = self.chunk_end(middle_idx); if offset < middle_end { - return self.binary_search(start_idx, start, middle_idx, middle_end, offset); + self.binary_search(start_idx, start, middle_idx, middle_end, offset) } else { - return self.binary_search(middle_idx + 1, middle_end, end_idx, end, offset); + self.binary_search(middle_idx + 1, middle_end, end_idx, end, offset) } } } @@ -366,7 +366,7 @@ impl std::io::Read for BufferedDynamicReader { self.read_offset += n as u64; - return Ok(n); + Ok(n) } } @@ -601,11 +601,11 @@ impl DynamicChunkWriter { (compressed_size*100)/(chunk_size as u64), is_duplicate, proxmox::tools::digest_to_hex(&digest)); self.index.add_chunk(self.chunk_offset as u64, &digest)?; self.chunk_buffer.truncate(0); - return Ok(()); + Ok(()) } Err(err) => { self.chunk_buffer.truncate(0); - return Err(err); + Err(err) } } } diff --git a/src/backup/fixed_index.rs b/src/backup/fixed_index.rs index 9dbdada8..991f621a 100644 --- a/src/backup/fixed_index.rs +++ b/src/backup/fixed_index.rs @@ -539,7 +539,7 @@ impl std::io::Read for BufferedFixedReader { self.read_offset += n as u64; - return Ok(n); + Ok(n) } } diff --git a/src/backup/index.rs b/src/backup/index.rs index ec455214..977ed109 100644 --- a/src/backup/index.rs +++ b/src/backup/index.rs @@ -84,9 +84,9 @@ impl std::io::Read for DigestListEncoder { break; } } - return Ok(written); + Ok(written) } else { - return Ok(0); + Ok(0) } } } diff --git a/src/cli/command.rs b/src/cli/command.rs index 05e5092f..5b4a3216 100644 --- a/src/cli/command.rs +++ b/src/cli/command.rs @@ -423,7 +423,6 @@ fn print_help_completion(def: &CommandLineInterface, help_cmd: &CliCommand, args match def { CommandLineInterface::Simple(_) => { print_simple_completion(help_cmd, &mut done, &help_cmd.arg_param, &help_cmd.arg_param, args); - return; } CommandLineInterface::Nested(map) => { if args.is_empty() { @@ -463,7 +462,6 @@ fn print_nested_completion(def: &CommandLineInterface, args: &[String]) { record_done_argument(&mut done, &cli_cmd.info.parameters, &key, &value); }); print_simple_completion(cli_cmd, &mut done, &cli_cmd.arg_param, &cli_cmd.arg_param, args); - return; } CommandLineInterface::Nested(map) => { if args.is_empty() { diff --git a/src/cli/getopts.rs b/src/cli/getopts.rs index 457aade8..2b1088ea 100644 --- a/src/cli/getopts.rs +++ b/src/cli/getopts.rs @@ -46,10 +46,10 @@ fn parse_argument(arg: &str) -> RawArgument { } } - return RawArgument::Option { + RawArgument::Option { name: unsafe { arg.get_unchecked(first..).to_string() }, value: None, - }; + } } /// parse as many arguments as possible into a Vec. This does not @@ -95,7 +95,7 @@ pub (crate) fn parse_argument_list>( if (pos + 1) < args.len() { let next = args[pos + 1].as_ref(); - if let RawArgument::Argument { value: _ } = parse_argument(next) { + if let RawArgument::Argument { .. } = parse_argument(next) { next_is_argument = true; if let Ok(_) = parse_boolean(next) { next_is_bool = true; @@ -114,15 +114,12 @@ pub (crate) fn parse_argument_list>( "missing boolean value.")); } + } else if next_is_argument { + pos += 1; + data.push((name, args[pos].as_ref().to_string())); } else { - - if next_is_argument { - pos += 1; - data.push((name, args[pos].as_ref().to_string())); - } else { - errors.push(format_err!("parameter '{}': {}", name, - "missing parameter value.")); - } + errors.push(format_err!("parameter '{}': {}", name, + "missing parameter value.")); } } Some(v) => { @@ -171,10 +168,8 @@ pub fn parse_arguments>( if let Schema::Array(_) = param_schema.as_ref() { last_arg_param_is_array = true; } - } else { - if *optional { - panic!("positional argument '{}' may not be optional", name); - } + } else if *optional { + panic!("positional argument '{}' may not be optional", name); } } else { panic!("no such property '{}' in schema", name); @@ -192,15 +187,13 @@ pub fn parse_arguments>( if !(is_last_arg_param && last_arg_param_is_optional) { errors.push(format_err!("missing argument '{}'", name)); } - } else { - if is_last_arg_param && last_arg_param_is_array { - for value in rest { - data.push((name.to_string(), value)); - } - rest = vec![]; - } else { - data.push((name.to_string(), rest.remove(0))); + } else if is_last_arg_param && last_arg_param_is_array { + for value in rest { + data.push((name.to_string(), value)); } + rest = vec![]; + } else { + data.push((name.to_string(), rest.remove(0))); } } diff --git a/src/client/backup_writer.rs b/src/client/backup_writer.rs index a5785e81..c1688e5a 100644 --- a/src/client/backup_writer.rs +++ b/src/client/backup_writer.rs @@ -506,7 +506,7 @@ impl BackupWriter { .and_then(move |_| { let repeat = repeat2.load(Ordering::SeqCst); let stream_len = stream_len2.load(Ordering::SeqCst); - let speed = ((stream_len*1000000)/(1024*1024))/(start_time.elapsed().as_micros() as usize); + let speed = ((stream_len*1_000_000)/(1024*1024))/(start_time.elapsed().as_micros() as usize); println!("Uploaded {} chunks in {} seconds ({} MB/s).", repeat, start_time.elapsed().as_secs(), speed); if repeat > 0 { println!("Average chunk size was {} bytes.", stream_len/repeat); @@ -559,7 +559,7 @@ impl BackupWriter { let _ = upload_result.await?; println!("Uploaded {} chunks in {} seconds.", repeat, start_time.elapsed().as_secs()); - let speed = ((item_len*1000000*(repeat as usize))/(1024*1024))/(start_time.elapsed().as_micros() as usize); + let speed = ((item_len*1_000_000*(repeat as usize))/(1024*1024))/(start_time.elapsed().as_micros() as usize); println!("Time per request: {} microseconds.", (start_time.elapsed().as_micros())/(repeat as u128)); Ok(speed) diff --git a/src/client/http_client.rs b/src/client/http_client.rs index 1ff1994c..2399e3eb 100644 --- a/src/client/http_client.rs +++ b/src/client/http_client.rs @@ -617,7 +617,7 @@ impl H2Client { .header("User-Agent", "proxmox-backup-client/1.0") .header(hyper::header::CONTENT_TYPE, content_type) .body(())?; - return Ok(request); + Ok(request) } else { let url: Uri = format!("https://{}:8007/{}", server, path).parse()?; let request = Request::builder() diff --git a/src/client/pipe_to_stream.rs b/src/client/pipe_to_stream.rs index 604d0155..f6a6a4be 100644 --- a/src/client/pipe_to_stream.rs +++ b/src/client/pipe_to_stream.rs @@ -45,20 +45,18 @@ impl Future for PipeToSendStream { None => return Poll::Ready(Err(format_err!("protocol canceled"))), } } - } else { - if let Poll::Ready(reset) = this.body_tx.poll_reset(cx) { - return Poll::Ready(Err(match reset { - Ok(reason) => format_err!("stream received RST_STREAM: {:?}", reason), - Err(err) => Error::from(err), - })); - } + } else if let Poll::Ready(reset) = this.body_tx.poll_reset(cx) { + return Poll::Ready(Err(match reset { + Ok(reason) => format_err!("stream received RST_STREAM: {:?}", reason), + Err(err) => Error::from(err), + })); } this.body_tx .send_data(this.data.take().unwrap(), true) .map_err(Error::from)?; - return Poll::Ready(Ok(())); + Poll::Ready(Ok(())) } else { if let Poll::Ready(reset) = this.body_tx.poll_reset(cx) { return Poll::Ready(Err(match reset { @@ -66,7 +64,7 @@ impl Future for PipeToSendStream { Err(err) => Error::from(err), })); } - return Poll::Ready(Ok(())); + Poll::Ready(Ok(())) } } } diff --git a/src/pxar/encoder.rs b/src/pxar/encoder.rs index 0a44b40a..c916b67d 100644 --- a/src/pxar/encoder.rs +++ b/src/pxar/encoder.rs @@ -217,7 +217,7 @@ impl<'a, W: Write, C: BackupCatalogWriter> Encoder<'a, W, C> { } let flags = flags::feature_flags_from_chattr(attr as u32); - entry.flags = entry.flags | flags; + entry.flags |= flags; Ok(()) } @@ -242,7 +242,7 @@ impl<'a, W: Write, C: BackupCatalogWriter> Encoder<'a, W, C> { } let flags = flags::feature_flags_from_fat_attr(attr); - entry.flags = entry.flags | flags; + entry.flags |= flags; Ok(()) } @@ -700,9 +700,9 @@ impl<'a, W: Write, C: BackupCatalogWriter> Encoder<'a, W, C> { if include_children { // Exclude patterns passed via the CLI are stored as '.pxarexclude-cli' // in the root directory of the archive. - if is_root && match_pattern.len() > 0 { + if is_root && !match_pattern.is_empty() { let filename = CString::new(".pxarexclude-cli")?; - name_list.push((filename, dir_stat.clone(), match_pattern.clone())); + name_list.push((filename, *dir_stat, match_pattern.clone())); } for entry in dir.iter() { @@ -1231,7 +1231,7 @@ impl<'a, W: Write, C: BackupCatalogWriter> Encoder<'a, W, C> { fn match_filename( filename: &CStr, stat: &FileStat, - match_pattern: &Vec, + match_pattern: &[MatchPattern], ) -> Result<(MatchType, Vec), Error> { let mut child_pattern = Vec::new(); let mut match_state = MatchType::None; diff --git a/src/pxar/flags.rs b/src/pxar/flags.rs index 81215b77..9e5c23dd 100644 --- a/src/pxar/flags.rs +++ b/src/pxar/flags.rs @@ -167,7 +167,7 @@ pub fn feature_flags_from_chattr(attr: u32) -> u64 { let mut flags = 0u64; for (fe_flag, fs_flag) in &CHATTR_MAP { - if (attr & fs_flag) != 0 { flags = flags | fe_flag; } + if (attr & fs_flag) != 0 { flags |= fe_flag; } } flags @@ -189,7 +189,7 @@ pub fn feature_flags_from_fat_attr(attr: u32) -> u64 { let mut flags = 0u64; for (fe_flag, fs_flag) in &FAT_ATTR_MAP { - if (attr & fs_flag) != 0 { flags = flags | fe_flag; } + if (attr & fs_flag) != 0 { flags |= fe_flag; } } flags diff --git a/src/pxar/sequential_decoder.rs b/src/pxar/sequential_decoder.rs index 7a0cae07..79c0adce 100644 --- a/src/pxar/sequential_decoder.rs +++ b/src/pxar/sequential_decoder.rs @@ -132,11 +132,7 @@ impl Result<(), Error>> SequentialDecoder { bail!("found invalid filename '.' or '..'."); } - if buffer - .iter() - .find(|b| (**b == b'/' || **b == b'\0')) - .is_some() - { + if buffer.iter().any(|b| (*b == b'/' || *b == b'\0')) { bail!("found invalid filename with slashes or nul bytes."); } @@ -332,7 +328,7 @@ impl Result<(), Error>> SequentialDecoder { fn restore_xattrs_fcaps_fd( &mut self, fd: RawFd, - xattrs: &Vec, + xattrs: &[PxarXAttr], fcaps: &Option, ) -> Result<(), Error> { for xattr in xattrs { @@ -679,7 +675,7 @@ impl Result<(), Error>> SequentialDecoder { entry: PxarEntry, filename: &OsStr, matched: MatchType, - match_pattern: &Vec, + match_pattern: &[MatchPattern], ) -> Result<(), Error> { let (mut head, attr) = self .read_attributes() @@ -727,7 +723,7 @@ impl Result<(), Error>> SequentialDecoder { /// Restore an archive into the specified directory. /// /// The directory is created if it does not exist. - pub fn restore(&mut self, path: &Path, match_pattern: &Vec) -> Result<(), Error> { + pub fn restore(&mut self, path: &Path, match_pattern: &[MatchPattern]) -> Result<(), Error> { let _ = std::fs::create_dir(path); let dir = nix::dir::Dir::open( @@ -739,7 +735,7 @@ impl Result<(), Error>> SequentialDecoder { let fd = dir.as_raw_fd(); let mut dirs = PxarDirStack::new(fd); // An empty match pattern list indicates to restore the full archive. - let matched = if match_pattern.len() == 0 { + let matched = if match_pattern.is_empty() { MatchType::Positive } else { MatchType::None @@ -786,7 +782,7 @@ impl Result<(), Error>> SequentialDecoder { dirs: &mut PxarDirStack, filename: &OsStr, parent_matched: MatchType, - match_pattern: &Vec, + match_pattern: &[MatchPattern], ) -> Result<(), Error> { let relative_path = dirs.as_path_buf(); let full_path = base_path.join(&relative_path).join(filename); @@ -811,7 +807,7 @@ impl Result<(), Error>> SequentialDecoder { // This is especially the case when the full archive is restored and // there are no match pattern. let mut matched = parent_matched; - if match_pattern.len() > 0 { + if !match_pattern.is_empty() { match match_filename(filename, ifmt == libc::S_IFDIR, match_pattern)? { (MatchType::None, _) => matched = MatchType::None, (MatchType::Negative, _) => matched = MatchType::Negative, @@ -1105,7 +1101,7 @@ impl Result<(), Error>> SequentialDecoder { fn match_filename( filename: &OsStr, is_dir: bool, - match_pattern: &Vec, + match_pattern: &[MatchPattern], ) -> Result<(MatchType, Vec), Error> { let mut child_pattern = Vec::new(); let mut match_state = MatchType::None; @@ -1146,7 +1142,7 @@ fn file_openat( mode: Mode, ) -> Result { let fd = - filename.with_nix_path(|cstr| nix::fcntl::openat(parent, cstr.as_ref(), flags, mode))??; + filename.with_nix_path(|cstr| nix::fcntl::openat(parent, cstr, flags, mode))??; let file = unsafe { std::fs::File::from_raw_fd(fd) }; diff --git a/src/server/rest.rs b/src/server/rest.rs index af3b74b2..d91b2621 100644 --- a/src/server/rest.rs +++ b/src/server/rest.rs @@ -1,4 +1,5 @@ use std::collections::HashMap; +use std::hash::BuildHasher; use std::path::{Path, PathBuf}; use std::pin::Pin; use std::sync::Arc; @@ -119,7 +120,7 @@ impl tower_service::Service> for ApiService { let path = req.uri().path().to_owned(); let method = req.method().clone(); - let peer = self.peer.clone(); + let peer = self.peer; Pin::from(handle_request(self.api_config.clone(), req)) .map(move |result| match result { Ok(res) => { @@ -144,11 +145,11 @@ impl tower_service::Service> for ApiService { } } -fn get_request_parameters_async( +fn get_request_parameters_async( info: &'static ApiMethod, parts: Parts, req_body: Body, - uri_param: HashMap, + uri_param: HashMap, ) -> Box> + Send> { let mut is_json = false; @@ -162,7 +163,7 @@ fn get_request_parameters_async( is_json = true; } _ => { - return Box::new(future::err(http_err!(BAD_REQUEST, format!("unsupported content type")))); + return Box::new(future::err(http_err!(BAD_REQUEST, "unsupported content type".to_string()))); } } } @@ -174,7 +175,7 @@ fn get_request_parameters_async( acc.extend_from_slice(&*chunk); Ok(acc) } else { - Err(http_err!(BAD_REQUEST, format!("Request body too large"))) + Err(http_err!(BAD_REQUEST, "Request body too large".to_string())) } }) .and_then(move |body| async move { @@ -195,11 +196,10 @@ fn get_request_parameters_async( let mut param_list: Vec<(String, String)> = vec![]; - if utf8.len() > 0 { + if !utf8.is_empty() { for (k, v) in form_urlencoded::parse(utf8.as_bytes()).into_owned() { param_list.push((k, v)); } - } if let Some(query_str) = parts.uri.query() { @@ -260,13 +260,13 @@ fn proxy_protected_request( }) } -pub fn handle_sync_api_request( +pub fn handle_sync_api_request( mut rpcenv: Env, info: &'static ApiMethod, formatter: &'static OutputFormatter, parts: Parts, req_body: Body, - uri_param: HashMap, + uri_param: HashMap, ) -> BoxFut { let params = get_request_parameters_async(info, parts, req_body, uri_param); @@ -339,7 +339,7 @@ pub fn handle_async_api_request( match (info.handler)(parts, req_body, params, info, Box::new(rpcenv)) { Ok(future) => future, Err(err) => { - let resp = (formatter.format_error)(Error::from(err)); + let resp = (formatter.format_error)(err); Box::new(future::ok(resp)) } } @@ -348,9 +348,9 @@ pub fn handle_async_api_request( fn get_index(username: Option, token: Option) -> Response { let nodename = proxmox::tools::nodename(); - let username = username.unwrap_or(String::from("")); + let username = username.unwrap_or_else(|| String::from("")); - let token = token.unwrap_or(String::from("")); + let token = token.unwrap_or_else(|| String::from("")); let setup = json!({ "Setup": { "auth_cookie_name": "PBSAuthCookie" }, @@ -614,7 +614,7 @@ pub fn handle_request(api: Arc, req: Request) -> BoxFut { // not Auth required for accessing files! if method != hyper::Method::GET { - return Box::new(future::err(http_err!(BAD_REQUEST, format!("Unsupported method")))); + return Box::new(future::err(http_err!(BAD_REQUEST, "Unsupported method".to_string()))); } if comp_len == 0 { diff --git a/src/server/state.rs b/src/server/state.rs index 8236ea6a..dd1c9fda 100644 --- a/src/server/state.rs +++ b/src/server/state.rs @@ -22,7 +22,6 @@ pub struct ServerState { pub reload_request: bool, } - lazy_static! { static ref SERVER_STATE: Mutex = Mutex::new(ServerState { mode: ServerMode::Normal, @@ -69,11 +68,7 @@ pub fn server_state_init() -> Result<(), Error> { pub fn is_reload_request() -> bool { let data = SERVER_STATE.lock().unwrap(); - if data.mode == ServerMode::Shutdown && data.reload_request { - true - } else { - false - } + data.mode == ServerMode::Shutdown && data.reload_request } pub fn server_shutdown() { diff --git a/src/server/worker_task.rs b/src/server/worker_task.rs index abb2d47a..341f4a9a 100644 --- a/src/server/worker_task.rs +++ b/src/server/worker_task.rs @@ -43,16 +43,10 @@ lazy_static! { pub fn worker_is_active(upid: &UPID) -> bool { if (upid.pid == *MY_PID) && (upid.pstart == *MY_PID_PSTART) { - if WORKER_TASK_LIST.lock().unwrap().contains_key(&upid.task_id) { - true - } else { - false - } + WORKER_TASK_LIST.lock().unwrap().contains_key(&upid.task_id) } else { - match proxmox::sys::linux::procfs::check_process_running_pstart(upid.pid, upid.pstart) { - Some(_) => true, - _ => false, - } + use proxmox::sys::linux::procfs; + procfs::check_process_running_pstart(upid.pid, upid.pstart).is_some() } } @@ -63,17 +57,17 @@ pub fn create_task_control_socket() -> Result<(), Error> { let control_future = super::create_control_socket(socketname, |param| { let param = param.as_object() - .ok_or(format_err!("unable to parse parameters (expected json object)"))?; + .ok_or_else(|| format_err!("unable to parse parameters (expected json object)"))?; if param.keys().count() != 2 { bail!("wrong number of parameters"); } let command = param.get("command") - .ok_or(format_err!("unable to parse parameters (missing command)"))?; + .ok_or_else(|| format_err!("unable to parse parameters (missing command)"))?; // this is the only command for now if command != "abort-task" { bail!("got unknown command '{}'", command); } let upid_str = param["upid"].as_str() - .ok_or(format_err!("unable to parse parameters (missing upid)"))?; + .ok_or_else(|| format_err!("unable to parse parameters (missing upid)"))?; let upid = upid_str.parse::()?; @@ -244,7 +238,8 @@ fn update_active_workers(new_upid: Option<&UPID>) -> Result, E match state { None => { println!("Detected stoped UPID {}", upid_str); - let status = upid_read_status(&upid).unwrap_or(String::from("unknown")); + let status = upid_read_status(&upid) + .unwrap_or_else(|_| String::from("unknown")); finish_list.push(TaskListInfo { upid, upid_str, state: Some((Local::now().timestamp(), status)) }); diff --git a/src/storage/config.rs b/src/storage/config.rs index ea8d4987..2f04fd42 100644 --- a/src/storage/config.rs +++ b/src/storage/config.rs @@ -31,9 +31,7 @@ fn register_storage_plugins() -> SectionConfig { pub fn parse_config(filename: &str, raw: &str) -> Result { - let res = STORAGE_SECTION_CONFIG.parse(filename, raw); - - res + STORAGE_SECTION_CONFIG.parse(filename, raw) } pub fn write_config(filename: &str, config: &SectionConfigData) -> Result { diff --git a/src/tools.rs b/src/tools.rs index fb2154d8..891934ad 100644 --- a/src/tools.rs +++ b/src/tools.rs @@ -3,6 +3,7 @@ //! This is a collection of small and useful tools. use std::any::Any; use std::collections::HashMap; +use std::hash::BuildHasher; use std::fs::{File, OpenOptions}; use std::io::ErrorKind; use std::io::Read; @@ -202,7 +203,7 @@ where pub fn getpwnam_ugid(username: &str) -> Result<(libc::uid_t, libc::gid_t), Error> { let c_username = std::ffi::CString::new(username).unwrap(); let info = unsafe { libc::getpwnam(c_username.as_ptr()) }; - if info == std::ptr::null_mut() { + if info.is_null() { bail!("getwpnam '{}' failed", username); } @@ -296,14 +297,14 @@ pub fn required_array_property<'a>(param: &'a Value, name: &str) -> Result) -> Vec { +pub fn complete_file_name(arg: &str, _param: &HashMap) -> Vec { let mut result = vec![]; use nix::fcntl::AtFlags; use nix::fcntl::OFlag; use nix::sys::stat::Mode; - let mut dirname = std::path::PathBuf::from(if arg.len() == 0 { "./" } else { arg }); + let mut dirname = std::path::PathBuf::from(if arg.is_empty() { "./" } else { arg }); let is_dir = match nix::sys::stat::fstatat(libc::AT_FDCWD, &dirname, AtFlags::empty()) { Ok(stat) => (stat.st_mode & libc::S_IFMT) == libc::S_IFDIR, @@ -426,7 +427,7 @@ pub fn join(data: &Vec, sep: char) -> String { let mut list = String::new(); for item in data { - if list.len() != 0 { + if !list.is_empty() { list.push(sep); } list.push_str(item); @@ -449,7 +450,7 @@ pub fn normalize_uri_path(path: &str) -> Result<(String, Vec<&str>), Error> { if name.is_empty() { continue; } - if name.starts_with(".") { + if name.starts_with('.') { bail!("Path contains illegal components."); } path.push('/'); diff --git a/src/tools/acl.rs b/src/tools/acl.rs index 09bf16db..1abbd459 100644 --- a/src/tools/acl.rs +++ b/src/tools/acl.rs @@ -111,7 +111,7 @@ impl ACL { Ok(ACL { ptr }) } - pub fn create_entry<'a>(&'a mut self) -> Result, nix::errno::Errno> { + pub fn create_entry(&mut self) -> Result { let mut ptr = ptr::null_mut() as *mut c_void; let res = unsafe { acl_create_entry(&mut self.ptr, &mut ptr) }; if res < 0 { diff --git a/src/tools/broadcast_future.rs b/src/tools/broadcast_future.rs index 71118da8..9c238e4b 100644 --- a/src/tools/broadcast_future.rs +++ b/src/tools/broadcast_future.rs @@ -7,6 +7,7 @@ use futures::future::{FutureExt, TryFutureExt}; use tokio::sync::oneshot; /// Broadcast results to registered listeners using asnyc oneshot channels +#[derive(Default)] pub struct BroadcastData { result: Option>, listeners: Vec>>, @@ -85,7 +86,7 @@ impl BroadcastFuture { let (tx, rx) = oneshot::channel::>(); let rx = rx .map_err(Error::from) - .and_then(|res| futures::future::ready(res)); + .and_then(futures::future::ready); (Self::new(Box::new(rx)), tx) } diff --git a/src/tools/daemon.rs b/src/tools/daemon.rs index 97215d54..febca8bd 100644 --- a/src/tools/daemon.rs +++ b/src/tools/daemon.rs @@ -28,6 +28,7 @@ pub trait Reloadable: Sized { /// Manages things to be stored and reloaded upon reexec. /// Anything which should be restorable should be instantiated via this struct's `restore` method, +#[derive(Default)] pub struct Reloader { pre_exec: Vec, } @@ -241,7 +242,7 @@ where } if let Err(e) = reloader.take().unwrap().fork_restart() { log::error!("error during reload: {}", e); - let _ = systemd_notify(SystemdNotify::Status(format!("error during reload"))); + let _ = systemd_notify(SystemdNotify::Status("error during reload".to_string())); } } else { log::info!("daemon shutting down..."); diff --git a/src/tools/fs.rs b/src/tools/fs.rs index 9eb48c6b..178105a8 100644 --- a/src/tools/fs.rs +++ b/src/tools/fs.rs @@ -131,7 +131,7 @@ where /// Filter by file name. Note that file names which aren't valid utf-8 will be treated as if /// they do not match the pattern. - fn filter_file_name_regex<'a>(self, regex: &'a Regex) -> FileNameRegexFilter<'a, Self, T, E> { + fn filter_file_name_regex(self, regex: &Regex) -> FileNameRegexFilter { FileNameRegexFilter { inner: self, regex } } } diff --git a/src/tools/process_locker.rs b/src/tools/process_locker.rs index 8f384d96..f0ccc76d 100644 --- a/src/tools/process_locker.rs +++ b/src/tools/process_locker.rs @@ -158,7 +158,7 @@ impl ProcessLocker { let data = locker.lock().unwrap(); - for (_k, v) in &data.shared_guard_list { + for v in data.shared_guard_list.values() { result = match result { None => Some(*v), Some(x) => if x < *v { Some(x) } else { Some(*v) }, diff --git a/src/tools/timer.rs b/src/tools/timer.rs index 5cb8997f..40877a19 100644 --- a/src/tools/timer.rs +++ b/src/tools/timer.rs @@ -87,6 +87,7 @@ pub struct Timer { } /// Timer specification used to arm a `Timer`. +#[derive(Default)] pub struct TimerSpec { /// The timeout to the next timer event. pub value: Option, diff --git a/src/tools/tty.rs b/src/tools/tty.rs index 715b21ae..a3ece89a 100644 --- a/src/tools/tty.rs +++ b/src/tools/tty.rs @@ -32,7 +32,7 @@ pub fn read_password(query: &str) -> Result, Error> { bail!("tcgetattr() failed"); } let mut termios = unsafe { termios.assume_init() }; - let old_termios = termios.clone(); + let old_termios = termios; // termios is a 'Copy' type unsafe { libc::cfmakeraw(&mut termios); } @@ -58,7 +58,7 @@ pub fn read_password(query: &str) -> Result, Error> { } 0x7F => { // backspace - if password.len() > 0 { + if !password.is_empty() { password.pop(); if asterisks { let _ignore_error = out.write_all("\x08 \x08".as_bytes()); @@ -69,7 +69,7 @@ pub fn read_password(query: &str) -> Result, Error> { other => { password.push(other); if asterisks { - let _ignore_error = out.write_all("*".as_bytes()); + let _ignore_error = out.write_all(b"*"); let _ignore_error = out.flush(); } } diff --git a/src/tools/xattr.rs b/src/tools/xattr.rs index 006010b2..f5e2ed75 100644 --- a/src/tools/xattr.rs +++ b/src/tools/xattr.rs @@ -66,7 +66,7 @@ pub fn fgetxattr(fd: RawFd, name: &[u8]) -> Result, nix::errno::Errno> { pub fn fsetxattr(fd: RawFd, xattr: &PxarXAttr) -> Result<(), nix::errno::Errno> { let mut name = xattr.name.clone(); - name.push('\0' as u8); + name.push(b'\0'); let flags = 0 as libc::c_int; let result = unsafe { libc::fsetxattr(fd, name.as_ptr() as *const libc::c_char, xattr.value.as_ptr() as *const libc::c_void, xattr.value.len(), flags)