Skip to content

Commit

Permalink
Inline utils::current_dir()
Browse files Browse the repository at this point in the history
  • Loading branch information
djc committed Jun 5, 2024
1 parent 0102b04 commit e4fc3b7
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 14 deletions.
7 changes: 5 additions & 2 deletions src/bin/rustup-init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#![recursion_limit = "1024"]

use anyhow::{anyhow, Result};
use anyhow::{anyhow, Context, Result};
use cfg_if::cfg_if;
// Public macros require availability of the internal symbols
use rs_tracing::{
Expand All @@ -29,6 +29,7 @@ use rustup::cli::self_update;
use rustup::cli::setup_mode;
use rustup::currentprocess::{process, with_runtime, Process};
use rustup::env_var::RUST_RECURSION_COUNT_MAX;
use rustup::errors::RustupError;
use rustup::is_proxyable_tools;
use rustup::utils::utils::{self, ExitCode};

Expand Down Expand Up @@ -115,7 +116,9 @@ async fn run_rustup_inner() -> Result<utils::ExitCode> {

// Before we do anything else, ensure we know where we are and who we
// are because otherwise we cannot proceed usefully.
let current_dir = utils::current_dir()?;
let current_dir = process()
.current_dir()
.context(RustupError::LocatingWorkingDir)?;
utils::current_exe()?;

match process().name().as_deref() {
Expand Down
2 changes: 1 addition & 1 deletion src/currentprocess.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ impl Process {
}
}

pub(crate) fn current_dir(&self) -> io::Result<PathBuf> {
pub fn current_dir(&self) -> io::Result<PathBuf> {
match self {
Process::OSProcess(_) => env::current_dir(),
#[cfg(feature = "test")]
Expand Down
2 changes: 1 addition & 1 deletion src/dist/dist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ fn components_missing_msg(cs: &[Component], manifest: &ManifestV2, toolchain: &s
}

#[derive(Debug, ThisError)]
pub(crate) enum DistError {
pub enum DistError {
#[error("{}", components_missing_msg(.0, .1, .2))]
ToolchainComponentsMissing(Vec<Component>, Box<ManifestV2>, String),
#[error("no release found for '{0}'")]
Expand Down
2 changes: 1 addition & 1 deletion src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use crate::{
pub struct OperationError(pub anyhow::Error);

#[derive(ThisError, Debug)]
pub(crate) enum RustupError {
pub enum RustupError {
#[error("partially downloaded file may have been damaged and was removed, please try again")]
BrokenPartialFile,
#[error("component download failed for {0}")]
Expand Down
6 changes: 3 additions & 3 deletions src/toolchain/names.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ impl Display for MaybeOfficialToolchainName {
/// like setting overrides, or that depend on configuration, like calculating
/// the toolchain directory.
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord)]
pub(crate) enum ToolchainName {
pub enum ToolchainName {
Custom(CustomToolchainName),
Official(ToolchainDesc),
}
Expand Down Expand Up @@ -396,7 +396,7 @@ impl Display for LocalToolchainName {
/// A custom toolchain name, but not an official toolchain name
/// (e.g. my-custom-toolchain)
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord)]
pub(crate) struct CustomToolchainName(String);
pub struct CustomToolchainName(String);

impl CustomToolchainName {
fn validate(candidate: &str) -> Result<CustomToolchainName, InvalidName> {
Expand Down Expand Up @@ -433,7 +433,7 @@ impl Display for CustomToolchainName {
/// code execution in a rust dir, so as a partial mitigation is limited to
/// absolute paths.
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord)]
pub(crate) struct PathBasedToolchainName(PathBuf, String);
pub struct PathBasedToolchainName(PathBuf, String);

impl Display for PathBasedToolchainName {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
Expand Down
6 changes: 0 additions & 6 deletions src/utils/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -491,12 +491,6 @@ pub(crate) fn make_executable(path: &Path) -> Result<()> {
inner(path)
}

pub fn current_dir() -> Result<PathBuf> {
process()
.current_dir()
.context(RustupError::LocatingWorkingDir)
}

pub fn current_exe() -> Result<PathBuf> {
env::current_exe().context(RustupError::LocatingWorkingDir)
}
Expand Down

0 comments on commit e4fc3b7

Please sign in to comment.