clippy: us *_or_else with function calls
Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
This commit is contained in:
parent
b92cad0938
commit
e062ebbc29
@ -1493,7 +1493,7 @@ fn pxar_file_download(
|
||||
|
||||
let mut split = components.splitn(2, |c| *c == b'/');
|
||||
let pxar_name = std::str::from_utf8(split.next().unwrap())?;
|
||||
let file_path = split.next().ok_or(format_err!("filepath looks strange '{}'", filepath))?;
|
||||
let file_path = split.next().ok_or_else(|| format_err!("filepath looks strange '{}'", filepath))?;
|
||||
let (manifest, files) = read_backup_index(&datastore, &backup_dir)?;
|
||||
for file in files {
|
||||
if file.filename == pxar_name && file.crypt_mode == Some(CryptMode::Encrypt) {
|
||||
@ -1520,7 +1520,7 @@ fn pxar_file_download(
|
||||
let root = decoder.open_root().await?;
|
||||
let file = root
|
||||
.lookup(OsStr::from_bytes(file_path)).await?
|
||||
.ok_or(format_err!("error opening '{:?}'", file_path))?;
|
||||
.ok_or_else(|| format_err!("error opening '{:?}'", file_path))?;
|
||||
|
||||
let body = match file.kind() {
|
||||
EntryKind::File { .. } => Body::wrap_stream(
|
||||
|
@ -88,7 +88,7 @@ pub fn do_sync_job(
|
||||
let worker_future = async move {
|
||||
|
||||
let delete = sync_job.remove_vanished.unwrap_or(true);
|
||||
let sync_owner = sync_job.owner.unwrap_or(Authid::root_auth_id().clone());
|
||||
let sync_owner = sync_job.owner.unwrap_or_else(|| Authid::root_auth_id().clone());
|
||||
let (client, src_repo, tgt_store) = get_pull_parameters(&sync_job.store, &sync_job.remote, &sync_job.remote_store).await?;
|
||||
|
||||
worker.log(format!("Starting datastore sync job '{}'", job_id));
|
||||
|
@ -638,7 +638,7 @@ impl std::str::FromStr for Authid {
|
||||
.iter()
|
||||
.rposition(|&b| b == b'!')
|
||||
.map(|pos| if pos < name_len { id.len() } else { pos })
|
||||
.unwrap_or(id.len());
|
||||
.unwrap_or_else(|| id.len());
|
||||
|
||||
if realm_end == id.len() - 1 {
|
||||
bail!("empty token name in userid");
|
||||
@ -670,7 +670,7 @@ impl TryFrom<String> for Authid {
|
||||
.iter()
|
||||
.rposition(|&b| b == b'!')
|
||||
.map(|pos| if pos < name_len { data.len() } else { pos })
|
||||
.unwrap_or(data.len());
|
||||
.unwrap_or_else(|| data.len());
|
||||
|
||||
if realm_end == data.len() - 1 {
|
||||
bail!("empty token name in userid");
|
||||
|
@ -97,7 +97,7 @@ where
|
||||
let info = this
|
||||
.index
|
||||
.chunk_info(idx)
|
||||
.ok_or(io_format_err!("could not get digest"))?;
|
||||
.ok_or_else(|| io_format_err!("could not get digest"))?;
|
||||
|
||||
this.current_chunk_offset = offset;
|
||||
this.current_chunk_idx = idx;
|
||||
|
@ -135,8 +135,8 @@ pub const DATASTORE_CFG_LOCKFILE: &str = "/etc/proxmox-backup/.datastore.lck";
|
||||
|
||||
pub fn config() -> Result<(SectionConfigData, [u8;32]), Error> {
|
||||
|
||||
let content = proxmox::tools::fs::file_read_optional_string(DATASTORE_CFG_FILENAME)?;
|
||||
let content = content.unwrap_or(String::from(""));
|
||||
let content = proxmox::tools::fs::file_read_optional_string(DATASTORE_CFG_FILENAME)?
|
||||
.unwrap_or_else(|| "".to_string());
|
||||
|
||||
let digest = openssl::sha::sha256(content.as_bytes());
|
||||
let data = CONFIG.parse(DATASTORE_CFG_FILENAME, &content)?;
|
||||
|
@ -68,8 +68,8 @@ pub fn lock() -> Result<std::fs::File, Error> {
|
||||
|
||||
pub fn config() -> Result<(SectionConfigData, [u8;32]), Error> {
|
||||
|
||||
let content = proxmox::tools::fs::file_read_optional_string(DRIVE_CFG_FILENAME)?;
|
||||
let content = content.unwrap_or(String::from(""));
|
||||
let content = proxmox::tools::fs::file_read_optional_string(DRIVE_CFG_FILENAME)?
|
||||
.unwrap_or_else(|| "".to_string());
|
||||
|
||||
let digest = openssl::sha::sha256(content.as_bytes());
|
||||
let data = CONFIG.parse(DRIVE_CFG_FILENAME, &content)?;
|
||||
|
@ -52,8 +52,8 @@ pub fn lock() -> Result<std::fs::File, Error> {
|
||||
|
||||
pub fn config() -> Result<(SectionConfigData, [u8;32]), Error> {
|
||||
|
||||
let content = proxmox::tools::fs::file_read_optional_string(MEDIA_POOL_CFG_FILENAME)?;
|
||||
let content = content.unwrap_or(String::from(""));
|
||||
let content = proxmox::tools::fs::file_read_optional_string(MEDIA_POOL_CFG_FILENAME)?
|
||||
.unwrap_or_else(|| "".to_string());
|
||||
|
||||
let digest = openssl::sha::sha256(content.as_bytes());
|
||||
let data = CONFIG.parse(MEDIA_POOL_CFG_FILENAME, &content)?;
|
||||
|
@ -386,9 +386,9 @@ impl NetworkConfig {
|
||||
pub fn check_mtu(&self, parent_name: &str, child_name: &str) -> Result<(), Error> {
|
||||
|
||||
let parent = self.interfaces.get(parent_name)
|
||||
.ok_or(format_err!("check_mtu - missing parent interface '{}'", parent_name))?;
|
||||
.ok_or_else(|| format_err!("check_mtu - missing parent interface '{}'", parent_name))?;
|
||||
let child = self.interfaces.get(child_name)
|
||||
.ok_or(format_err!("check_mtu - missing child interface '{}'", child_name))?;
|
||||
.ok_or_else(|| format_err!("check_mtu - missing child interface '{}'", child_name))?;
|
||||
|
||||
let child_mtu = match child.mtu {
|
||||
Some(mtu) => mtu,
|
||||
|
@ -92,8 +92,8 @@ pub const REMOTE_CFG_LOCKFILE: &str = "/etc/proxmox-backup/.remote.lck";
|
||||
|
||||
pub fn config() -> Result<(SectionConfigData, [u8;32]), Error> {
|
||||
|
||||
let content = proxmox::tools::fs::file_read_optional_string(REMOTE_CFG_FILENAME)?;
|
||||
let content = content.unwrap_or(String::from(""));
|
||||
let content = proxmox::tools::fs::file_read_optional_string(REMOTE_CFG_FILENAME)?
|
||||
.unwrap_or_else(|| "".to_string());
|
||||
|
||||
let digest = openssl::sha::sha256(content.as_bytes());
|
||||
let data = CONFIG.parse(REMOTE_CFG_FILENAME, &content)?;
|
||||
|
@ -183,8 +183,8 @@ pub const SYNC_CFG_LOCKFILE: &str = "/etc/proxmox-backup/.sync.lck";
|
||||
|
||||
pub fn config() -> Result<(SectionConfigData, [u8;32]), Error> {
|
||||
|
||||
let content = proxmox::tools::fs::file_read_optional_string(SYNC_CFG_FILENAME)?;
|
||||
let content = content.unwrap_or(String::from(""));
|
||||
let content = proxmox::tools::fs::file_read_optional_string(SYNC_CFG_FILENAME)?
|
||||
.unwrap_or_else(|| "".to_string());
|
||||
|
||||
let digest = openssl::sha::sha256(content.as_bytes());
|
||||
let data = CONFIG.parse(SYNC_CFG_FILENAME, &content)?;
|
||||
|
@ -157,8 +157,8 @@ pub const USER_CFG_LOCKFILE: &str = "/etc/proxmox-backup/.user.lck";
|
||||
|
||||
pub fn config() -> Result<(SectionConfigData, [u8;32]), Error> {
|
||||
|
||||
let content = proxmox::tools::fs::file_read_optional_string(USER_CFG_FILENAME)?;
|
||||
let content = content.unwrap_or(String::from(""));
|
||||
let content = proxmox::tools::fs::file_read_optional_string(USER_CFG_FILENAME)?
|
||||
.unwrap_or_else(|| "".to_string());
|
||||
|
||||
let digest = openssl::sha::sha256(content.as_bytes());
|
||||
let mut data = CONFIG.parse(USER_CFG_FILENAME, &content)?;
|
||||
|
@ -456,7 +456,7 @@ fn handlebars_humam_bytes_helper(
|
||||
) -> HelperResult {
|
||||
let param = h.param(0).map(|v| v.value().as_u64())
|
||||
.flatten()
|
||||
.ok_or(RenderError::new("human-bytes: param not found"))?;
|
||||
.ok_or_else(|| RenderError::new("human-bytes: param not found"))?;
|
||||
|
||||
out.write(&HumanByte::from(param).to_string())?;
|
||||
|
||||
@ -472,10 +472,10 @@ fn handlebars_relative_percentage_helper(
|
||||
) -> HelperResult {
|
||||
let param0 = h.param(0).map(|v| v.value().as_f64())
|
||||
.flatten()
|
||||
.ok_or(RenderError::new("relative-percentage: param0 not found"))?;
|
||||
.ok_or_else(|| RenderError::new("relative-percentage: param0 not found"))?;
|
||||
let param1 = h.param(1).map(|v| v.value().as_f64())
|
||||
.flatten()
|
||||
.ok_or(RenderError::new("relative-percentage: param1 not found"))?;
|
||||
.ok_or_else(|| RenderError::new("relative-percentage: param1 not found"))?;
|
||||
|
||||
if param1 == 0.0 {
|
||||
out.write("-")?;
|
||||
|
@ -147,7 +147,7 @@ fn log_response(
|
||||
let now = proxmox::tools::time::epoch_i64();
|
||||
// time format which apache/nginx use (by default), copied from pve-http-server
|
||||
let datetime = proxmox::tools::time::strftime_local("%d/%m/%Y:%H:%M:%S %z", now)
|
||||
.unwrap_or("-".into());
|
||||
.unwrap_or_else(|_| "-".to_string());
|
||||
|
||||
logfile
|
||||
.lock()
|
||||
@ -161,7 +161,7 @@ fn log_response(
|
||||
path,
|
||||
status.as_str(),
|
||||
resp.body().size_hint().lower(),
|
||||
user_agent.unwrap_or("-".into()),
|
||||
user_agent.unwrap_or_else(|| "-".to_string()),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
@ -330,7 +330,7 @@ pub fn rotate_task_log_archive(size_threshold: u64, compress: bool, max_files: O
|
||||
let _lock = lock_task_list_files(true)?;
|
||||
|
||||
let mut logrotate = LogRotate::new(PROXMOX_BACKUP_ARCHIVE_TASK_FN, compress)
|
||||
.ok_or(format_err!("could not get archive file names"))?;
|
||||
.ok_or_else(|| format_err!("could not get archive file names"))?;
|
||||
|
||||
logrotate.rotate(size_threshold, None, max_files)
|
||||
}
|
||||
|
@ -85,12 +85,12 @@ pub fn linux_tape_changer_list() -> Vec<TapeDeviceInfo> {
|
||||
let vendor = device.property_value("ID_VENDOR")
|
||||
.map(std::ffi::OsString::from)
|
||||
.and_then(|s| if let Ok(s) = s.into_string() { Some(s) } else { None })
|
||||
.unwrap_or(String::from("unknown"));
|
||||
.unwrap_or_else(|| String::from("unknown"));
|
||||
|
||||
let model = device.property_value("ID_MODEL")
|
||||
.map(std::ffi::OsString::from)
|
||||
.and_then(|s| if let Ok(s) = s.into_string() { Some(s) } else { None })
|
||||
.unwrap_or(String::from("unknown"));
|
||||
.unwrap_or_else(|| String::from("unknown"));
|
||||
|
||||
let dev_path = format!("/dev/tape/by-id/scsi-{}", serial);
|
||||
|
||||
@ -166,12 +166,12 @@ pub fn linux_tape_device_list() -> Vec<TapeDeviceInfo> {
|
||||
let vendor = device.property_value("ID_VENDOR")
|
||||
.map(std::ffi::OsString::from)
|
||||
.and_then(|s| if let Ok(s) = s.into_string() { Some(s) } else { None })
|
||||
.unwrap_or(String::from("unknown"));
|
||||
.unwrap_or_else(|| String::from("unknown"));
|
||||
|
||||
let model = device.property_value("ID_MODEL")
|
||||
.map(std::ffi::OsString::from)
|
||||
.and_then(|s| if let Ok(s) = s.into_string() { Some(s) } else { None })
|
||||
.unwrap_or(String::from("unknown"));
|
||||
.unwrap_or_else(|| String::from("unknown"));
|
||||
|
||||
let dev_path = format!("/dev/tape/by-id/scsi-{}-nst", serial);
|
||||
|
||||
|
@ -522,7 +522,7 @@ impl Inventory {
|
||||
) -> Result<String, Error> {
|
||||
|
||||
if let Some(ctime) = self.media_set_start_time(media_set_uuid) {
|
||||
let mut template = template.unwrap_or(String::from("%c"));
|
||||
let mut template = template.unwrap_or_else(|| String::from("%c"));
|
||||
template = template.replace("%id%", &media_set_uuid.to_string());
|
||||
proxmox::tools::time::strftime_local(&template, ctime)
|
||||
} else {
|
||||
|
@ -89,9 +89,9 @@ impl MediaPool {
|
||||
use_offline_media: bool,
|
||||
) -> Result<Self, Error> {
|
||||
|
||||
let allocation = config.allocation.clone().unwrap_or(String::from("continue")).parse()?;
|
||||
let allocation = config.allocation.clone().unwrap_or_else(|| String::from("continue")).parse()?;
|
||||
|
||||
let retention = config.retention.clone().unwrap_or(String::from("keep")).parse()?;
|
||||
let retention = config.retention.clone().unwrap_or_else(|| String::from("keep")).parse()?;
|
||||
|
||||
let encrypt_fingerprint = match config.encrypt {
|
||||
Some(ref fingerprint) => Some(fingerprint.parse()?),
|
||||
|
@ -104,8 +104,8 @@ impl LogRotate {
|
||||
|
||||
for i in (0..count-1).rev() {
|
||||
if self.compress
|
||||
&& filenames[i+0].extension().unwrap_or(std::ffi::OsStr::new("")) != "zst"
|
||||
&& filenames[i+1].extension().unwrap_or(std::ffi::OsStr::new("")) == "zst"
|
||||
&& filenames[i+0].extension() != Some(std::ffi::OsStr::new("zst"))
|
||||
&& filenames[i+1].extension() == Some(std::ffi::OsStr::new("zst"))
|
||||
{
|
||||
Self::compress(&filenames[i], &filenames[i+1], &options)?;
|
||||
} else {
|
||||
@ -204,7 +204,7 @@ impl Iterator for LogRotateFiles {
|
||||
let filename = self.file_names.next()?;
|
||||
let file = File::open(&filename).ok()?;
|
||||
|
||||
if filename.extension().unwrap_or(std::ffi::OsStr::new("")) == "zst" {
|
||||
if filename.extension() == Some(std::ffi::OsStr::new("zst")) {
|
||||
let encoder = zstd::stream::read::Decoder::new(file).ok()?;
|
||||
return Some(Box::new(encoder));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user