Missing cfg (#600)
* Check whether NPM root is owned by the current user (fix #599) * Missing cfg * Another missing config
This commit is contained in:
committed by
GitHub
parent
258acce481
commit
4fdafa0ba1
@@ -5,9 +5,12 @@ use crate::terminal::print_separator;
|
|||||||
use crate::utils::{require, PathExt};
|
use crate::utils::{require, PathExt};
|
||||||
use crate::{error::SkipStep, execution_context::ExecutionContext};
|
use crate::{error::SkipStep, execution_context::ExecutionContext};
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use log::debug;
|
|
||||||
|
|
||||||
use directories::BaseDirs;
|
use directories::BaseDirs;
|
||||||
|
use log::debug;
|
||||||
|
#[cfg(unix)]
|
||||||
|
use nix::unistd::Uid;
|
||||||
|
#[cfg(unix)]
|
||||||
|
use std::os::unix::prelude::MetadataExt;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
|
|
||||||
@@ -20,7 +23,7 @@ impl NPM {
|
|||||||
Self { command }
|
Self { command }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(target_os = "macos"))]
|
#[cfg(target_os = "linux")]
|
||||||
fn root(&self) -> Result<PathBuf> {
|
fn root(&self) -> Result<PathBuf> {
|
||||||
Command::new(&self.command)
|
Command::new(&self.command)
|
||||||
.args(&["root", "-g"])
|
.args(&["root", "-g"])
|
||||||
@@ -38,13 +41,17 @@ impl NPM {
|
|||||||
pub fn run_npm_upgrade(_base_dirs: &BaseDirs, run_type: RunType) -> Result<()> {
|
pub fn run_npm_upgrade(_base_dirs: &BaseDirs, run_type: RunType) -> Result<()> {
|
||||||
let npm = require("npm").map(NPM::new)?;
|
let npm = require("npm").map(NPM::new)?;
|
||||||
|
|
||||||
#[cfg(not(target_os = "macos"))]
|
#[cfg(target_os = "linux")]
|
||||||
{
|
{
|
||||||
let npm_root = npm.root()?;
|
let npm_root = npm.root()?;
|
||||||
if !npm_root.is_descendant_of(_base_dirs.home_dir()) {
|
let metadata = std::fs::metadata(&npm_root)?;
|
||||||
|
let uid = Uid::effective();
|
||||||
|
|
||||||
|
if metadata.uid() != uid.as_raw() {
|
||||||
return Err(SkipStep(format!(
|
return Err(SkipStep(format!(
|
||||||
"NPM root at {} isn't a decandent of the user's home directory",
|
"NPM root at {} is owned by {} which is not the current user",
|
||||||
npm_root.display()
|
npm_root.display(),
|
||||||
|
uid
|
||||||
))
|
))
|
||||||
.into());
|
.into());
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user