mirror of
https://github.com/philmmanjaro/alma.git
synced 2025-07-26 06:59:28 +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")]
|
||||
Interactive,
|
||||
|
||||
#[fail(display = "Failed umounting filesystems")]
|
||||
UmountFailure,
|
||||
}
|
||||
|
||||
impl Fail for Error {
|
||||
|
@ -210,6 +210,10 @@ fn create(command: CreateCommand) -> Result<(), Error> {
|
||||
}
|
||||
|
||||
info!("Unmounting filesystems");
|
||||
mount_stack.umount()?;
|
||||
|
||||
info!("Installation succeeded. It is now safe to unplug your device.");
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -1,3 +1,5 @@
|
||||
use super::error::{Error, ErrorKind};
|
||||
use failure::Fail;
|
||||
use log::{debug, warn};
|
||||
use nix;
|
||||
use nix::mount::{mount, umount, MsFlags};
|
||||
@ -48,15 +50,24 @@ impl<'a> MountStack<'a> {
|
||||
self.targets.push(target);
|
||||
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> {
|
||||
fn drop(&mut self) {
|
||||
while let Some(target) = self.targets.pop() {
|
||||
debug!("Unmounting {}", target.display());
|
||||
if !umount(target).is_ok() {
|
||||
warn!("Unable to umount {}", target.display());
|
||||
};
|
||||
}
|
||||
self.umount().ok();
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user