Change to use PWD env vairable to get current dir

Fixes 285.
This commit is contained in:
Shunsuke Mie 2021-11-01 22:55:01 +09:00 committed by Arijit Basu
parent 00030e44ff
commit f5131b08ab

View File

@ -115,6 +115,22 @@ pub struct Runner {
selection: Vec<PathBuf>,
}
// In unix system, the std::env::current_dir() calls libc getcwd() that
// returns physical path. As a workaround, this function tries to use `PWD`
// environment variable that is configured by shell.
fn get_current_dir() -> Result<PathBuf, std::io::Error> {
let cur = std::env::current_dir();
if let Ok(pwd) = std::env::var("PWD") {
if pwd.is_empty() {
cur
} else {
Ok(PathBuf::from(pwd))
}
} else {
cur
}
}
impl Runner {
/// Create a new runner object passing the default arguments
pub fn new() -> Result<Self> {
@ -123,7 +139,7 @@ impl Runner {
/// Create a new runner object passing the given arguments
pub fn from_cli(cli: Cli) -> Result<Self> {
let basedir = std::env::current_dir()?;
let basedir = get_current_dir()?;
let basedir_clone = basedir.clone();
let mut paths = cli.paths.into_iter().map(|p| {
if p.is_relative() {