From a4acb6ef847e080f639816554b23807d64896708 Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Fri, 31 Jul 2020 08:53:00 +0200 Subject: [PATCH] lock_file: return std::io::Error --- src/backup/backup_info.rs | 17 +++++++---------- src/tools.rs | 9 +++++---- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/src/backup/backup_info.rs b/src/backup/backup_info.rs index e77cc787..ba5ea1a3 100644 --- a/src/backup/backup_info.rs +++ b/src/backup/backup_info.rs @@ -11,6 +11,8 @@ use chrono::{DateTime, TimeZone, SecondsFormat, Utc}; use std::path::{PathBuf, Path}; use lazy_static::lazy_static; +use proxmox::sys::error::SysError; + use super::manifest::MANIFEST_BLOB_NAME; macro_rules! BACKUP_ID_RE { () => (r"[A-Za-z0-9][A-Za-z0-9_-]+") } @@ -155,19 +157,14 @@ impl BackupGroup { // backups could still take a very long time tools::lock_file(&mut handle, true, Some(Duration::from_nanos(0))) .map_err(|err| { - match err.downcast_ref::() { - Some(nix::Error::Sys(nix::errno::Errno::EAGAIN)) => { - return format_err!( - "unable to acquire lock on backup group {:?} - another backup is already running", - self.group_path(), - ); - }, - _ => () - } format_err!( "unable to acquire lock on backup group {:?} - {}", self.group_path(), - err, + if err.would_block() { + String::from("another backup is already running") + } else { + err.to_string() + } ) })?; diff --git a/src/tools.rs b/src/tools.rs index d7b72a73..c1045c16 100644 --- a/src/tools.rs +++ b/src/tools.rs @@ -17,6 +17,7 @@ use openssl::hash::{hash, DigestBytes, MessageDigest}; use percent_encoding::AsciiSet; use proxmox::tools::vec; +use proxmox::sys::error::SysResult; pub use proxmox::tools::fd::Fd; @@ -98,7 +99,7 @@ pub fn lock_file( file: &mut F, exclusive: bool, timeout: Option, -) -> Result<(), Error> { +) -> Result<(), io::Error> { let lockarg = if exclusive { nix::fcntl::FlockArg::LockExclusive } else { @@ -107,7 +108,7 @@ pub fn lock_file( let timeout = match timeout { None => { - nix::fcntl::flock(file.as_raw_fd(), lockarg)?; + nix::fcntl::flock(file.as_raw_fd(), lockarg).into_io_result()?; return Ok(()); } Some(t) => t, @@ -119,7 +120,7 @@ pub fn lock_file( } else { nix::fcntl::FlockArg::LockSharedNonblock }; - nix::fcntl::flock(file.as_raw_fd(), lockarg)?; + nix::fcntl::flock(file.as_raw_fd(), lockarg).into_io_result()?; return Ok(()); } @@ -138,7 +139,7 @@ pub fn lock_file( .interval(Some(Duration::from_millis(10))), )?; - nix::fcntl::flock(file.as_raw_fd(), lockarg)?; + nix::fcntl::flock(file.as_raw_fd(), lockarg).into_io_result()?; Ok(()) }