From: Ashe Connor Date: Fri, 20 Oct 2017 00:51:23 +0000 (+1100) Subject: Comments! X-Git-Tag: archive/raspbian/0.35.0-2+rpi1~3^2^2^2^2^2^2^2~22^2~5^2~28^2~2 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=e08efb519986df200fec99529e5d5a879fa00479;p=cargo.git Comments! --- diff --git a/src/cargo/util/config.rs b/src/cargo/util/config.rs index 4f523ed07..110f1de20 100644 --- a/src/cargo/util/config.rs +++ b/src/cargo/util/config.rs @@ -155,12 +155,19 @@ impl Config { pub fn cargo_exe(&self) -> CargoResult<&Path> { self.cargo_exe.get_or_try_init(|| { fn from_current_exe() -> CargoResult { + // Try fetching the path to `cargo` using env::current_exe(). + // The method varies per operating system and might fail; in particular, + // it depends on /proc being mounted on Linux, and some environments + // (like containers or chroots) may not have that available. env::current_exe() .and_then(|path| path.canonicalize()) .map_err(CargoError::from) } fn from_argv() -> CargoResult { + // Grab argv[0] and attempt to resolve it to an absolute path. + // Path::canonicalize succeeds only when the path is already absolute, + // or it's a relative path accessible from the current directory. env::args_os() .next() .ok_or(CargoError::from("no argv[0]")) @@ -169,7 +176,12 @@ impl Config { } fn probe_path(argv0: PathBuf) -> CargoResult { - // canonicalize failed, probe PATH if no dir sep in argv0 + // Path::canonicalize failed, so finally, if argv[0] has no directory + // separator in it, we look through the PATH environment variable checking + // for a matching file in each directory. + // A directory separator implies either (a) an absolute path, so we + // shouldn't check PATH, or (b) a relative path with a directory component, + // which wouldn't search PATH in any shell anyway. if argv0.components().count() > 1 { return Err(CargoError::from("no cargo executable candidate found")); }