lock_file: return std::io::Error
This commit is contained in:
parent
d7ee07d838
commit
a4acb6ef84
|
@ -11,6 +11,8 @@ use chrono::{DateTime, TimeZone, SecondsFormat, Utc};
|
||||||
use std::path::{PathBuf, Path};
|
use std::path::{PathBuf, Path};
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
|
|
||||||
|
use proxmox::sys::error::SysError;
|
||||||
|
|
||||||
use super::manifest::MANIFEST_BLOB_NAME;
|
use super::manifest::MANIFEST_BLOB_NAME;
|
||||||
|
|
||||||
macro_rules! BACKUP_ID_RE { () => (r"[A-Za-z0-9][A-Za-z0-9_-]+") }
|
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
|
// backups could still take a very long time
|
||||||
tools::lock_file(&mut handle, true, Some(Duration::from_nanos(0)))
|
tools::lock_file(&mut handle, true, Some(Duration::from_nanos(0)))
|
||||||
.map_err(|err| {
|
.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!(
|
format_err!(
|
||||||
"unable to acquire lock on backup group {:?} - {}",
|
"unable to acquire lock on backup group {:?} - {}",
|
||||||
self.group_path(),
|
self.group_path(),
|
||||||
err,
|
if err.would_block() {
|
||||||
|
String::from("another backup is already running")
|
||||||
|
} else {
|
||||||
|
err.to_string()
|
||||||
|
}
|
||||||
)
|
)
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,7 @@ use openssl::hash::{hash, DigestBytes, MessageDigest};
|
||||||
use percent_encoding::AsciiSet;
|
use percent_encoding::AsciiSet;
|
||||||
|
|
||||||
use proxmox::tools::vec;
|
use proxmox::tools::vec;
|
||||||
|
use proxmox::sys::error::SysResult;
|
||||||
|
|
||||||
pub use proxmox::tools::fd::Fd;
|
pub use proxmox::tools::fd::Fd;
|
||||||
|
|
||||||
|
@ -98,7 +99,7 @@ pub fn lock_file<F: AsRawFd>(
|
||||||
file: &mut F,
|
file: &mut F,
|
||||||
exclusive: bool,
|
exclusive: bool,
|
||||||
timeout: Option<Duration>,
|
timeout: Option<Duration>,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), io::Error> {
|
||||||
let lockarg = if exclusive {
|
let lockarg = if exclusive {
|
||||||
nix::fcntl::FlockArg::LockExclusive
|
nix::fcntl::FlockArg::LockExclusive
|
||||||
} else {
|
} else {
|
||||||
|
@ -107,7 +108,7 @@ pub fn lock_file<F: AsRawFd>(
|
||||||
|
|
||||||
let timeout = match timeout {
|
let timeout = match timeout {
|
||||||
None => {
|
None => {
|
||||||
nix::fcntl::flock(file.as_raw_fd(), lockarg)?;
|
nix::fcntl::flock(file.as_raw_fd(), lockarg).into_io_result()?;
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
Some(t) => t,
|
Some(t) => t,
|
||||||
|
@ -119,7 +120,7 @@ pub fn lock_file<F: AsRawFd>(
|
||||||
} else {
|
} else {
|
||||||
nix::fcntl::FlockArg::LockSharedNonblock
|
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(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -138,7 +139,7 @@ pub fn lock_file<F: AsRawFd>(
|
||||||
.interval(Some(Duration::from_millis(10))),
|
.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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue