Change to use `PWD` env vairable to get current dir

Fixes 285.
pull/397/head
Shunsuke Mie 3 years ago committed by Arijit Basu
parent 00030e44ff
commit f5131b08ab

@ -115,6 +115,22 @@ pub struct Runner {
selection: Vec<PathBuf>, 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 { impl Runner {
/// Create a new runner object passing the default arguments /// Create a new runner object passing the default arguments
pub fn new() -> Result<Self> { pub fn new() -> Result<Self> {
@ -123,7 +139,7 @@ impl Runner {
/// Create a new runner object passing the given arguments /// Create a new runner object passing the given arguments
pub fn from_cli(cli: Cli) -> Result<Self> { 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 basedir_clone = basedir.clone();
let mut paths = cli.paths.into_iter().map(|p| { let mut paths = cli.paths.into_iter().map(|p| {
if p.is_relative() { if p.is_relative() {

Loading…
Cancel
Save