mirror of
https://github.com/philmmanjaro/alma.git
synced 2025-07-26 23:19:29 +02:00
Fail if failed to ummount the filesystems
This commit is contained in:
parent
4efa7668c8
commit
7c8109934c
@ -55,6 +55,9 @@ pub enum ErrorKind {
|
|||||||
|
|
||||||
#[fail(display = "Error caused by the interactive mode")]
|
#[fail(display = "Error caused by the interactive mode")]
|
||||||
Interactive,
|
Interactive,
|
||||||
|
|
||||||
|
#[fail(display = "Failed umounting filesystems")]
|
||||||
|
UmountFailure,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Fail for Error {
|
impl Fail for Error {
|
||||||
|
@ -210,6 +210,10 @@ fn create(command: CreateCommand) -> Result<(), Error> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
info!("Unmounting filesystems");
|
info!("Unmounting filesystems");
|
||||||
|
mount_stack.umount()?;
|
||||||
|
|
||||||
|
info!("Installation succeeded. It is now safe to unplug your device.");
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
use super::error::{Error, ErrorKind};
|
||||||
|
use failure::Fail;
|
||||||
use log::{debug, warn};
|
use log::{debug, warn};
|
||||||
use nix;
|
use nix;
|
||||||
use nix::mount::{mount, umount, MsFlags};
|
use nix::mount::{mount, umount, MsFlags};
|
||||||
@ -48,15 +50,24 @@ impl<'a> MountStack<'a> {
|
|||||||
self.targets.push(target);
|
self.targets.push(target);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn umount(&mut self) -> Result<(), Error> {
|
||||||
|
let mut result = Ok(());
|
||||||
|
|
||||||
|
while let Some(target) = self.targets.pop() {
|
||||||
|
debug!("Unmounting {}", target.display());
|
||||||
|
if let Err(e) = umount(target) {
|
||||||
|
warn!("Unable to umount {}: {}", target.display(), e);
|
||||||
|
result = Err(Error::from(e.context(ErrorKind::UmountFailure)));
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
result
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Drop for MountStack<'a> {
|
impl<'a> Drop for MountStack<'a> {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
while let Some(target) = self.targets.pop() {
|
self.umount().ok();
|
||||||
debug!("Unmounting {}", target.display());
|
|
||||||
if !umount(target).is_ok() {
|
|
||||||
warn!("Unable to umount {}", target.display());
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user