mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-31 04:23:40 +00:00
add richer error codes to disk import
This commit is contained in:
committed by
Aiden McClelland
parent
547d1a0856
commit
133b793953
@@ -1,9 +1,11 @@
|
|||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
|
|
||||||
|
use color_eyre::eyre::eyre;
|
||||||
use tokio::process::Command;
|
use tokio::process::Command;
|
||||||
use tracing::instrument;
|
use tracing::instrument;
|
||||||
|
|
||||||
|
use super::util::pvscan;
|
||||||
use crate::disk::mount::filesystem::block_dev::mount;
|
use crate::disk::mount::filesystem::block_dev::mount;
|
||||||
use crate::disk::mount::util::unmount;
|
use crate::disk::mount::util::unmount;
|
||||||
use crate::util::Invoke;
|
use crate::util::Invoke;
|
||||||
@@ -13,8 +15,6 @@ pub const PASSWORD_PATH: &'static str = "/etc/embassy/password";
|
|||||||
pub const DEFAULT_PASSWORD: &'static str = "password";
|
pub const DEFAULT_PASSWORD: &'static str = "password";
|
||||||
pub const MAIN_FS_SIZE: FsSize = FsSize::Gigabytes(8);
|
pub const MAIN_FS_SIZE: FsSize = FsSize::Gigabytes(8);
|
||||||
|
|
||||||
// TODO: use IncorrectDisk / DiskNotAvailable / DiskCorrupted
|
|
||||||
|
|
||||||
#[instrument(skip(disks, datadir, password))]
|
#[instrument(skip(disks, datadir, password))]
|
||||||
pub async fn create<I, P>(
|
pub async fn create<I, P>(
|
||||||
disks: &I,
|
disks: &I,
|
||||||
@@ -195,6 +195,29 @@ pub async fn export<P: AsRef<Path>>(guid: &str, datadir: P) -> Result<(), Error>
|
|||||||
|
|
||||||
#[instrument(skip(datadir, password))]
|
#[instrument(skip(datadir, password))]
|
||||||
pub async fn import<P: AsRef<Path>>(guid: &str, datadir: P, password: &str) -> Result<(), Error> {
|
pub async fn import<P: AsRef<Path>>(guid: &str, datadir: P, password: &str) -> Result<(), Error> {
|
||||||
|
let scan = pvscan().await?;
|
||||||
|
if scan
|
||||||
|
.values()
|
||||||
|
.filter_map(|a| a.as_ref())
|
||||||
|
.filter(|a| a.starts_with("EMBASSY_"))
|
||||||
|
.next()
|
||||||
|
.is_none()
|
||||||
|
{
|
||||||
|
return Err(Error::new(
|
||||||
|
eyre!("Embassy disk not found."),
|
||||||
|
crate::ErrorKind::DiskNotAvailable,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
if !scan
|
||||||
|
.values()
|
||||||
|
.filter_map(|a| a.as_ref())
|
||||||
|
.any(|id| id == guid)
|
||||||
|
{
|
||||||
|
return Err(Error::new(
|
||||||
|
eyre!("An Embassy disk was found, but it is not the correct disk for this device."),
|
||||||
|
crate::ErrorKind::IncorrectDisk,
|
||||||
|
));
|
||||||
|
}
|
||||||
match Command::new("vgimport")
|
match Command::new("vgimport")
|
||||||
.arg(guid)
|
.arg(guid)
|
||||||
.invoke(crate::ErrorKind::DiskManagement)
|
.invoke(crate::ErrorKind::DiskManagement)
|
||||||
|
|||||||
Reference in New Issue
Block a user