]> git.proxmox.com Git - proxmox-backup.git/commitdiff
lock_file: return std::io::Error
authorDietmar Maurer <dietmar@proxmox.com>
Fri, 31 Jul 2020 06:53:00 +0000 (08:53 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Fri, 31 Jul 2020 06:53:00 +0000 (08:53 +0200)
src/backup/backup_info.rs
src/tools.rs

index e77cc7870957d0b7d4a54d84009c6bbb3dd8e780..ba5ea1a30ca93dd129f8caa8cc1b9b30d6b130eb 100644 (file)
@@ -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::<nix::Error>() {
-                    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()
+                    }
                 )
             })?;
 
index d7b72a733537641228f41e8c7e6b3fa2957ff22d..c1045c16222c0ad10d0201fba9f0b316f9e6f416 100644 (file)
@@ -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<F: AsRawFd>(
     file: &mut F,
     exclusive: bool,
     timeout: Option<Duration>,
-) -> Result<(), Error> {
+) -> Result<(), io::Error> {
     let lockarg = if exclusive {
         nix::fcntl::FlockArg::LockExclusive
     } else {
@@ -107,7 +108,7 @@ pub fn lock_file<F: AsRawFd>(
 
     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<F: AsRawFd>(
         } 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<F: AsRawFd>(
             .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(())
 }