summaryrefslogtreecommitdiffstats
path: root/vendor/home
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--vendor/home/.cargo-checksum.json2
-rw-r--r--vendor/home/Cargo.toml26
-rw-r--r--vendor/home/src/env.rs106
-rw-r--r--vendor/home/src/lib.rs48
4 files changed, 136 insertions, 46 deletions
diff --git a/vendor/home/.cargo-checksum.json b/vendor/home/.cargo-checksum.json
index 637f4c5ce..ad8175dc3 100644
--- a/vendor/home/.cargo-checksum.json
+++ b/vendor/home/.cargo-checksum.json
@@ -1 +1 @@
-{"files":{"Cargo.toml":"f6ea8042d794bed2af227905011daada5eaa1eb15ba63589d2aa9c8bd5ea06e7","LICENSE-APACHE":"aefbb3792184d86e625cd877b226a00e2cf13cb546ae79e78ddb9e3f097a7156","LICENSE-MIT":"ea7c5138df175c35e89b7adc1b1b35e07786a40330cae4beb2172781bd3daad9","README.md":"13b381ff7553b3467c85b877ee0aae43ebf444deca1c85131d5f0fb3b27d5003","src/lib.rs":"bbadf2a9750a1dd204057dee19e4282d48a878bd9b1810bedf59dc4b55a992eb","src/windows.rs":"061ce6208d2a366cdbf9d094c60fa73b7e856eb1f510fa2aaf5d109bded35442"},"package":"2456aef2e6b6a9784192ae780c0f15bc57df0e918585282325e8c8ac27737654"} \ No newline at end of file
+{"files":{"Cargo.toml":"12996f8286ac1164cb7026f8e170316337a0acb2d180fbf41192ddcf534a4843","LICENSE-APACHE":"aefbb3792184d86e625cd877b226a00e2cf13cb546ae79e78ddb9e3f097a7156","LICENSE-MIT":"ea7c5138df175c35e89b7adc1b1b35e07786a40330cae4beb2172781bd3daad9","README.md":"13b381ff7553b3467c85b877ee0aae43ebf444deca1c85131d5f0fb3b27d5003","src/env.rs":"4e8bd91330f6ae948f5b825e9884720631f4fe9282fb4548915218e1c43b54a5","src/lib.rs":"cc2675a4c0d5b2e3041228554718f63f754811e9b45a3c9b423bd2f43adf38e3","src/windows.rs":"061ce6208d2a366cdbf9d094c60fa73b7e856eb1f510fa2aaf5d109bded35442"},"package":"747309b4b440c06d57b0b25f2aee03ee9b5e5397d288c60e21fc709bb98a7408"} \ No newline at end of file
diff --git a/vendor/home/Cargo.toml b/vendor/home/Cargo.toml
index 245d5e1d8..765a5f903 100644
--- a/vendor/home/Cargo.toml
+++ b/vendor/home/Cargo.toml
@@ -3,24 +3,34 @@
# When uploading crates to the registry Cargo will automatically
# "normalize" Cargo.toml files for maximal compatibility
# with all versions of Cargo and also rewrite `path` dependencies
-# to registry (e.g., crates.io) dependencies
+# to registry (e.g., crates.io) dependencies.
#
-# If you believe there's an error in this file please file an
-# issue against the rust-lang/cargo repository. If you're
-# editing this file be aware that the upstream Cargo.toml
-# will likely look very different (and much more reasonable)
+# If you are reading this file be aware that the original Cargo.toml
+# will likely look very different (and much more reasonable).
+# See Cargo.toml.orig for the original contents.
[package]
edition = "2018"
name = "home"
-version = "0.5.3"
+version = "0.5.4"
authors = ["Brian Anderson <andersrb@gmail.com>"]
-include = ["/src", "/Cargo.toml", "/CHANGELOG", "/LICENSE-*", "/README.md"]
+include = [
+ "/src",
+ "/Cargo.toml",
+ "/CHANGELOG",
+ "/LICENSE-*",
+ "/README.md",
+]
description = "Shared definitions of home directories"
documentation = "https://docs.rs/home"
readme = "README.md"
license = "MIT OR Apache-2.0"
repository = "https://github.com/brson/home"
+
[target."cfg(windows)".dependencies.winapi]
version = "0.3"
-features = ["shlobj", "std", "winerror"]
+features = [
+ "shlobj",
+ "std",
+ "winerror",
+]
diff --git a/vendor/home/src/env.rs b/vendor/home/src/env.rs
new file mode 100644
index 000000000..e47273bc8
--- /dev/null
+++ b/vendor/home/src/env.rs
@@ -0,0 +1,106 @@
+//! Lower-level utilities for mocking the process environment.
+
+use std::{
+ ffi::OsString,
+ io,
+ path::{Path, PathBuf},
+};
+
+/// Permits parameterizing the home functions via the _from variants - used for
+/// in-process unit testing by rustup.
+pub trait Env {
+ /// Return the path to the the users home dir, or None if any error occurs:
+ /// see home_inner.
+ fn home_dir(&self) -> Option<PathBuf>;
+ /// Return the current working directory.
+ fn current_dir(&self) -> io::Result<PathBuf>;
+ /// Get an environment variable, as per std::env::var_os.
+ fn var_os(&self, key: &str) -> Option<OsString>;
+}
+
+/// Implements Env for the OS context, both Unix style and Windows.
+///
+/// This is trait permits in-process testing by providing a control point to
+/// allow in-process divergence on what is normally process wide state.
+///
+/// Implementations should be provided by whatever testing framework the caller
+/// is using. Code that is not performing in-process threaded testing requiring
+/// isolated rustup/cargo directories does not need this trait or the _from
+/// functions.
+pub struct OsEnv;
+impl Env for OsEnv {
+ fn home_dir(&self) -> Option<PathBuf> {
+ crate::home_dir_inner()
+ }
+ fn current_dir(&self) -> io::Result<PathBuf> {
+ std::env::current_dir()
+ }
+ fn var_os(&self, key: &str) -> Option<OsString> {
+ std::env::var_os(key)
+ }
+}
+
+pub const OS_ENV: OsEnv = OsEnv {};
+
+/// Returns the path of the current user's home directory from [`Env::home_dir`].
+pub fn home_dir_with_env(env: &dyn Env) -> Option<PathBuf> {
+ env.home_dir()
+}
+
+/// Variant of cargo_home where the environment source is parameterized. This is
+/// specifically to support in-process testing scenarios as environment
+/// variables and user home metadata are normally process global state. See the
+/// [`Env`] trait.
+pub fn cargo_home_with_env(env: &dyn Env) -> io::Result<PathBuf> {
+ let cwd = env.current_dir()?;
+ cargo_home_with_cwd_env(env, &cwd)
+}
+
+/// Variant of cargo_home_with_cwd where the environment source is
+/// parameterized. This is specifically to support in-process testing scenarios
+/// as environment variables and user home metadata are normally process global
+/// state. See the OsEnv trait.
+pub fn cargo_home_with_cwd_env(env: &dyn Env, cwd: &Path) -> io::Result<PathBuf> {
+ match env.var_os("CARGO_HOME").filter(|h| !h.is_empty()) {
+ Some(home) => {
+ let home = PathBuf::from(home);
+ if home.is_absolute() {
+ Ok(home)
+ } else {
+ Ok(cwd.join(&home))
+ }
+ }
+ _ => home_dir_with_env(env)
+ .map(|p| p.join(".cargo"))
+ .ok_or_else(|| io::Error::new(io::ErrorKind::Other, "could not find cargo home dir")),
+ }
+}
+
+/// Variant of cargo_home_with_cwd where the environment source is
+/// parameterized. This is specifically to support in-process testing scenarios
+/// as environment variables and user home metadata are normally process global
+/// state. See the OsEnv trait.
+pub fn rustup_home_with_env(env: &dyn Env) -> io::Result<PathBuf> {
+ let cwd = env.current_dir()?;
+ rustup_home_with_cwd_env(env, &cwd)
+}
+
+/// Variant of cargo_home_with_cwd where the environment source is
+/// parameterized. This is specifically to support in-process testing scenarios
+/// as environment variables and user home metadata are normally process global
+/// state. See the OsEnv trait.
+pub fn rustup_home_with_cwd_env(env: &dyn Env, cwd: &Path) -> io::Result<PathBuf> {
+ match env.var_os("RUSTUP_HOME").filter(|h| !h.is_empty()) {
+ Some(home) => {
+ let home = PathBuf::from(home);
+ if home.is_absolute() {
+ Ok(home)
+ } else {
+ Ok(cwd.join(&home))
+ }
+ }
+ _ => home_dir_with_env(env)
+ .map(|d| d.join(".rustup"))
+ .ok_or_else(|| io::Error::new(io::ErrorKind::Other, "could not find rustup home dir")),
+ }
+}
diff --git a/vendor/home/src/lib.rs b/vendor/home/src/lib.rs
index ad31d3d2e..ad254ca3b 100644
--- a/vendor/home/src/lib.rs
+++ b/vendor/home/src/lib.rs
@@ -25,13 +25,14 @@
//!
//! [discussion]: https://github.com/rust-lang/rust/pull/46799#issuecomment-361156935
-#![doc(html_root_url = "https://docs.rs/home/0.5.3")]
+#![doc(html_root_url = "https://docs.rs/home/0.5.4")]
#![deny(rust_2018_idioms)]
+pub mod env;
+
#[cfg(windows)]
mod windows;
-use std::env;
use std::io;
use std::path::{Path, PathBuf};
@@ -48,10 +49,9 @@ use std::path::{Path, PathBuf};
///
/// Returns the value of the `USERPROFILE` environment variable if it
/// is set and not equal to the empty string. If both do not exist,
-/// [`GetUserProfileDirectory`][msdn] is used to return the
-/// appropriate path.
+/// [`SHGetFolderPathW`][msdn] is used to return the appropriate path.
///
-/// [msdn]: https://docs.microsoft.com/en-us/windows/win32/api/userenv/nf-userenv-getuserprofiledirectoryw
+/// [msdn]: https://docs.microsoft.com/en-us/windows/win32/api/shlobj_core/nf-shlobj_core-shgetfolderpathw
///
/// # Examples
///
@@ -62,7 +62,7 @@ use std::path::{Path, PathBuf};
/// }
/// ```
pub fn home_dir() -> Option<PathBuf> {
- home_dir_inner()
+ env::home_dir_with_env(&env::OS_ENV)
}
#[cfg(windows)]
@@ -71,7 +71,7 @@ use windows::home_dir_inner;
#[cfg(any(unix, target_os = "redox"))]
fn home_dir_inner() -> Option<PathBuf> {
#[allow(deprecated)]
- env::home_dir()
+ std::env::home_dir()
}
/// Returns the storage directory used by Cargo, often knowns as
@@ -102,26 +102,13 @@ fn home_dir_inner() -> Option<PathBuf> {
/// }
/// ```
pub fn cargo_home() -> io::Result<PathBuf> {
- let cwd = env::current_dir()?;
- cargo_home_with_cwd(&cwd)
+ env::cargo_home_with_env(&env::OS_ENV)
}
/// Returns the storage directory used by Cargo within `cwd`.
/// For more details, see [`cargo_home`](fn.cargo_home.html).
pub fn cargo_home_with_cwd(cwd: &Path) -> io::Result<PathBuf> {
- match env::var_os("CARGO_HOME").filter(|h| !h.is_empty()) {
- Some(home) => {
- let home = PathBuf::from(home);
- if home.is_absolute() {
- Ok(home)
- } else {
- Ok(cwd.join(&home))
- }
- }
- _ => home_dir()
- .map(|p| p.join(".cargo"))
- .ok_or_else(|| io::Error::new(io::ErrorKind::Other, "could not find cargo home dir")),
- }
+ env::cargo_home_with_cwd_env(&env::OS_ENV, cwd)
}
/// Returns the storage directory used by rustup, often knowns as
@@ -152,24 +139,11 @@ pub fn cargo_home_with_cwd(cwd: &Path) -> io::Result<PathBuf> {
/// }
/// ```
pub fn rustup_home() -> io::Result<PathBuf> {
- let cwd = env::current_dir()?;
- rustup_home_with_cwd(&cwd)
+ env::rustup_home_with_env(&env::OS_ENV)
}
/// Returns the storage directory used by rustup within `cwd`.
/// For more details, see [`rustup_home`](fn.rustup_home.html).
pub fn rustup_home_with_cwd(cwd: &Path) -> io::Result<PathBuf> {
- match env::var_os("RUSTUP_HOME").filter(|h| !h.is_empty()) {
- Some(home) => {
- let home = PathBuf::from(home);
- if home.is_absolute() {
- Ok(home)
- } else {
- Ok(cwd.join(&home))
- }
- }
- _ => home_dir()
- .map(|d| d.join(".rustup"))
- .ok_or_else(|| io::Error::new(io::ErrorKind::Other, "could not find rustup home dir")),
- }
+ env::rustup_home_with_cwd_env(&env::OS_ENV, cwd)
}