mirror of
https://github.com/philmmanjaro/alma.git
synced 2025-12-06 19:39:20 +01:00
Refactor main.rs and fix clippy lints
Status: WIP Completed: * Fixed flagged clippy lints * Moved qemu(), main.rs::mount() and chroot() to the tools module. * Moved constants in main.rs to constants.rs (including base packages array) * Renamed Presets struct to PresetsCollection to avoid confusion with Preset struct * Moved main() to the top of main.rs to highlight general logic path * Added comments and docstrings to some functions * Removed some uses of `use foo::*` to make the source of imported functions and structs clearer TODO: * Move remaining code in main.rs to modules (except main()) * Break up create() function in to separate steps * Log every command run (with arguments) to debug! when verbose flag is used * Add docstrings for remaining functions and document constants (e.g. why noatime is used) * Remove remaining uses of `use foo::*` * Consider renaming/moving tools module to address tool:: vs. Tool:: confusion
This commit is contained in:
@@ -9,8 +9,8 @@ use std::io::Read;
|
||||
use std::marker::PhantomData;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
static LUKS_MAGIC_1: &'static [u8] = &[0x4c, 0x55, 0x4b, 0x53, 0xba, 0xbe];
|
||||
static LUKS_MAGIC_2: &'static [u8] = &[0x53, 0x4b, 0x55, 0x4c, 0xba, 0xbe];
|
||||
static LUKS_MAGIC_1: &[u8] = &[0x4c, 0x55, 0x4b, 0x53, 0xba, 0xbe];
|
||||
static LUKS_MAGIC_2: &[u8] = &[0x53, 0x4b, 0x55, 0x4c, 0xba, 0xbe];
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct EncryptedDevice<'t, 'o> {
|
||||
|
||||
@@ -21,9 +21,7 @@ impl LoopDevice {
|
||||
.context(ErrorKind::Image)?;
|
||||
|
||||
if !output.status.success() {
|
||||
Err(ErrorKind::Losetup(
|
||||
String::from_utf8(output.stderr).unwrap(),
|
||||
))?
|
||||
return Err(ErrorKind::Losetup(String::from_utf8(output.stderr).unwrap()).into());
|
||||
}
|
||||
|
||||
let path = PathBuf::from(String::from_utf8(output.stdout).unwrap().trim());
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use std::path::Path;
|
||||
|
||||
// Marker traits
|
||||
pub trait BlockDevice: std::fmt::Debug {
|
||||
fn path(&self) -> &Path;
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ use super::Filesystem;
|
||||
use crate::error::{Error, ErrorKind};
|
||||
use failure::Fail;
|
||||
use log::{debug, warn};
|
||||
use nix;
|
||||
use nix::mount::{mount, umount, MsFlags};
|
||||
use std::marker::PhantomData;
|
||||
use std::path::PathBuf;
|
||||
@@ -20,7 +19,6 @@ impl<'a> MountStack<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn mount(
|
||||
&mut self,
|
||||
filesystem: &'a Filesystem,
|
||||
|
||||
@@ -31,8 +31,11 @@ impl<'a> StorageDevice<'a> {
|
||||
path,
|
||||
origin: PhantomData,
|
||||
};
|
||||
if !allow_non_removable && (!(_self.is_removable_device()? || _self.is_loop_device())) {
|
||||
return Err(ErrorKind::DangerousDevice)?;
|
||||
|
||||
// If we only allow removable/loop devices, and the device is neither removable or a loop
|
||||
// device then throw a DangerousDevice error
|
||||
if !(allow_non_removable || _self.is_removable_device()? || _self.is_loop_device()) {
|
||||
return Err(ErrorKind::DangerousDevice.into());
|
||||
}
|
||||
|
||||
Ok(_self)
|
||||
|
||||
Reference in New Issue
Block a user