Skip to content

Commit feaa58b

Browse files
committed
refactor: inline GlobalContext::get_path
1 parent d80156f commit feaa58b

File tree

2 files changed

+6
-16
lines changed

2 files changed

+6
-16
lines changed

src/cargo/ops/common_for_install_and_uninstall.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use crate::sources::source::QueryKind;
2121
use crate::sources::source::Source;
2222
use crate::util::GlobalContext;
2323
use crate::util::cache_lock::CacheLockMode;
24+
use crate::util::context::ConfigRelativePath;
2425
use crate::util::errors::CargoResult;
2526
use crate::util::{FileLock, Filesystem};
2627

@@ -545,11 +546,14 @@ impl InstallInfo {
545546

546547
/// Determines the root directory where installation is done.
547548
pub fn resolve_root(flag: Option<&str>, gctx: &GlobalContext) -> CargoResult<Filesystem> {
548-
let config_root = gctx.get_path("install.root")?;
549+
let config_root = gctx
550+
.get::<Option<ConfigRelativePath>>("install.root")?
551+
.map(|p| p.resolve_program(gctx));
552+
549553
Ok(flag
550554
.map(PathBuf::from)
551555
.or_else(|| gctx.get_env_os("CARGO_INSTALL_ROOT").map(PathBuf::from))
552-
.or_else(move || config_root.map(|v| v.val))
556+
.or_else(|| config_root)
553557
.map(Filesystem::new)
554558
.unwrap_or_else(|| gctx.home().clone()))
555559
}

src/cargo/util/context/mod.rs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -981,20 +981,6 @@ impl GlobalContext {
981981
self.get::<OptValue<String>>(key)
982982
}
983983

984-
/// Get a config value that is expected to be a path.
985-
///
986-
/// This returns a relative path if the value does not contain any
987-
/// directory separators. See `ConfigRelativePath::resolve_program` for
988-
/// more details.
989-
pub fn get_path(&self, key: &str) -> CargoResult<OptValue<PathBuf>> {
990-
self.get::<OptValue<ConfigRelativePath>>(key).map(|v| {
991-
v.map(|v| Value {
992-
val: v.val.resolve_program(self),
993-
definition: v.definition,
994-
})
995-
})
996-
}
997-
998984
fn string_to_path(&self, value: &str, definition: &Definition) -> PathBuf {
999985
let is_path = value.contains('/') || (cfg!(windows) && value.contains('\\'));
1000986
if is_path {

0 commit comments

Comments
 (0)