Skip to content

Commit

Permalink
Fixed a bug where drive names were calculated badly
Browse files Browse the repository at this point in the history
This could result in situations where for example there was a single drive
named 'Drive2'. The user can then not create any more drives because the
nexts drive name would be 'Drive2' (because the calculation is just drive
count + 1). Now we just look for the first available name
  • Loading branch information
ALSchwalm committed Oct 2, 2018
1 parent 063a8a3 commit 09fe8cc
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
4 changes: 1 addition & 3 deletions pISO/src/newdrive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -425,9 +425,7 @@ impl input::Input for DriveFormat {
return Ok((false, vec![]));
}
_ => {
let count = self.vg.volumes()?.len() + 1;

let name = format!("Drive{}", count);
let name = utils::next_available_drive_name(&self.vg)?;
let mut volume = self.vg.create_volume(&name, self.size)?;

DriveFormat::format_volume(&mut volume, &self.selected, &name)?;
Expand Down
13 changes: 12 additions & 1 deletion pISO/src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use error::{Result, ResultExt};
use lvm;
use error::{ErrorKind, Result, ResultExt};
use std::ffi::OsStr;
use std::fmt::Debug;
use std::process::Command;
Expand Down Expand Up @@ -44,3 +45,13 @@ where
}
Err(format!("timeout while waiting for {}", path.as_ref().display()).into())
}

pub fn next_available_drive_name(vg: &lvm::VolumeGroup) -> Result<String> {
let volumes = vg.volumes()?;
for num in 1.. {
if volumes.iter().all(|vol| vol.name != format!("Drive{}", num)) {
return Ok(format!("Drive{}", num))
}
}
Err(ErrorKind::Msg("Failed to find valid drive number".into()).into())
}

0 comments on commit 09fe8cc

Please sign in to comment.