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) {
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(
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));
.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");
.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");
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;
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)?;
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)?;
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)?;
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,
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)?;
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)?;
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)?;
) -> 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())?;
) -> 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("-")?;
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()
path,
status.as_str(),
resp.body().size_hint().lower(),
- user_agent.unwrap_or("-".into()),
+ user_agent.unwrap_or_else(|| "-".to_string()),
));
}
}
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)
}
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);
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);
) -> 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 {
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()?),
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 {
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));
}