Merge branch 'main' into hoverbear/ds-436-tidy-up-plan-install-ux

This commit is contained in:
Ana Hobden 2022-11-10 08:49:32 -08:00
commit fb70f9d21b
3 changed files with 21 additions and 3 deletions

View file

@ -40,3 +40,7 @@ impl CommandExecute for HarmonicCli {
}
}
}
pub fn is_root() -> bool {
nix::unistd::getuid() == nix::unistd::Uid::from_raw(0)
}

View file

@ -3,7 +3,9 @@ use std::{
process::ExitCode,
};
use crate::{action::ActionState, plan::RECEIPT_LOCATION, BuiltinPlanner, InstallPlan, Planner};
use crate::{
action::ActionState, cli::is_root, plan::RECEIPT_LOCATION, BuiltinPlanner, InstallPlan, Planner,
};
use clap::{ArgAction, Parser};
use eyre::{eyre, WrapErr};
@ -48,6 +50,12 @@ impl CommandExecute for Install {
explain,
} = self;
if !is_root() {
return Err(eyre!(
"`harmonic install` must be run as `root`, try `sudo harmonic install`"
));
}
let existing_receipt: Option<InstallPlan> = match Path::new(RECEIPT_LOCATION).exists() {
true => {
let install_plan_string = tokio::fs::read_to_string(&RECEIPT_LOCATION)

View file

@ -1,8 +1,8 @@
use std::{path::PathBuf, process::ExitCode};
use crate::{plan::RECEIPT_LOCATION, InstallPlan};
use crate::{cli::is_root, plan::RECEIPT_LOCATION, InstallPlan};
use clap::{ArgAction, Parser};
use eyre::WrapErr;
use eyre::{eyre, WrapErr};
use crate::{cli::CommandExecute, interaction};
@ -37,6 +37,12 @@ impl CommandExecute for Uninstall {
explain,
} = self;
if !is_root() {
return Err(eyre!(
"`harmonic install` must be run as `root`, try `sudo harmonic install`"
));
}
let install_receipt_string = tokio::fs::read_to_string(receipt)
.await
.wrap_err("Reading receipt")?;