Skip to content

Commit

Permalink
little bit of refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
madonuko committed Oct 17, 2023
1 parent d974d49 commit a0a1962
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 31 deletions.
19 changes: 7 additions & 12 deletions src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,6 @@ impl Bootloader {
/// Currently only works for PC, no mac support
fn mkefiboot(&self, chroot: &Path, _: &Manifest) -> Result<()> {
let tree = chroot.parent().unwrap().join(ISO_TREE);
let tmp = PathBuf::from("/tmp/katsu.efiboot");
std::fs::create_dir_all(&tmp)?;
// glob the funny

// TODO: Add mac boot support

Expand Down Expand Up @@ -424,11 +421,9 @@ pub fn run_script(script: Script, chroot: &Path, in_chroot: bool) -> Result<()>
Ok(())
}

pub fn run_all_scripts(scripts: &[Script], chroot: &Path, in_chroot: bool) -> Result<()> {
let mut scrs: HashMap<String, (Script, bool)> = HashMap::new();
scripts.iter().for_each(|s| {
scrs.insert(s.id.clone().unwrap_or("<?>".into()), (s.clone(), false));
});
pub fn run_all_scripts(scrs: &[Script], chroot: &Path, in_chroot: bool) -> Result<()> {
let scrs =
scrs.iter().map(|s| (s.id.clone().unwrap_or("<?>".into()), (s.clone(), false))).collect();
run_scripts(scrs, chroot, in_chroot)
}

Expand Down Expand Up @@ -523,7 +518,7 @@ impl ImageBuilder for DiskImageBuilder {

self.root_builder.build(&chroot.canonicalize()?, manifest)?;

disk.unmount_from_chroot(&ldp, chroot)?;
disk.unmount_from_chroot()?;
loopdev.detach()?;

Ok(())
Expand All @@ -540,11 +535,11 @@ pub struct DeviceInstaller {

impl ImageBuilder for DeviceInstaller {
fn build(
&self, _chroot: &Path, _image: &Path, _manifest: &Manifest, skip_phases: &SkipPhases,
&self, _chroot: &Path, _image: &Path, _manifest: &Manifest, _skip_phases: &SkipPhases,
) -> Result<()> {
todo!();
self.root_builder.build(_chroot, _manifest)?;
Ok(())
// self.root_builder.build(_chroot, _manifest)?;
// Ok(())
}
}

Expand Down
22 changes: 6 additions & 16 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,6 @@ impl PartitionLayout {

pub fn get_index(&self, mountpoint: &str) -> Option<usize> {
// index should be +1 of the actual partition number (sda1 is index 0)

self.partitions.iter().position(|p| p.mountpoint == mountpoint).map(|i| i + 1)
}

Expand Down Expand Up @@ -284,7 +283,6 @@ impl PartitionLayout {

ordered.sort_unstable_by(|(_, a), (_, b)| {
// trim trailing slashes

let am = a.mountpoint.trim_end_matches('/').matches('/').count();
let bm = b.mountpoint.trim_end_matches('/').matches('/').count();
if a.mountpoint == "/" {
Expand Down Expand Up @@ -327,24 +325,16 @@ impl PartitionLayout {
Ok(())
}

pub fn unmount_from_chroot(&self, disk: &Path, chroot: &Path) -> Result<()> {
pub fn unmount_from_chroot(&self) -> Result<()> {
// unmount partitions from chroot

// sort partitions by mountpoint
let ordered = self.sort_partitions().into_iter().rev().collect::<Vec<_>>();

for (index, part) in &ordered {
let devname = partition_name(&disk.to_string_lossy(), *index);

// clean the mountpoint so we don't have the slash at the start
let mp_cleaned = part.mountpoint.trim_start_matches('/');
let mountpoint = chroot.join(mp_cleaned);

std::fs::create_dir_all(&mountpoint)?;

trace!("umount {devname} {mountpoint:?}");
let ordered =
self.sort_partitions().into_iter().map(|(_, p)| p.mountpoint).rev().collect::<Vec<_>>();

cmd_lib::run_cmd!(umount $devname 2>&1)?;
for mp in &ordered {
trace!("umount {mp}");
cmd_lib::run_cmd!(umount $mp 2>&1)?;
}
Ok(())
}
Expand Down
3 changes: 0 additions & 3 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,3 @@ pub fn run_with_chroot<T>(root: &Path, f: impl FnOnce() -> Result<T>) -> Result<
unmount_chroot(root)?;
res
}



0 comments on commit a0a1962

Please sign in to comment.