@@ -71,10 +71,6 @@ pub fn pushd(path: impl Into<PathBuf>) -> Pushd {
7171 Pushd { _p : ( ) }
7272}
7373
74- pub fn pwd ( ) -> PathBuf {
75- Env :: with ( |env| env. cwd ( ) )
76- }
77-
7874impl Drop for Pushd {
7975 fn drop ( & mut self ) {
8076 Env :: with ( |env| env. popd ( ) )
@@ -101,14 +97,15 @@ pub fn run_process(cmd: String, echo: bool) -> Result<String> {
10197fn run_process_inner ( cmd : & str , echo : bool ) -> Result < String > {
10298 let mut args = shelx ( cmd) ;
10399 let binary = args. remove ( 0 ) ;
100+ let current_dir = Env :: with ( |it| it. cwd ( ) . to_path_buf ( ) ) ;
104101
105102 if echo {
106103 println ! ( "> {}" , cmd)
107104 }
108105
109106 let output = Command :: new ( binary)
110107 . args ( args)
111- . current_dir ( pwd ( ) )
108+ . current_dir ( current_dir )
112109 . stdin ( Stdio :: null ( ) )
113110 . stderr ( Stdio :: inherit ( ) )
114111 . output ( ) ?;
@@ -130,27 +127,30 @@ fn shelx(cmd: &str) -> Vec<String> {
130127 cmd. split_whitespace ( ) . map ( |it| it. to_string ( ) ) . collect ( )
131128}
132129
133- #[ derive( Default ) ]
134130struct Env {
135131 pushd_stack : Vec < PathBuf > ,
136132}
137133
138134impl Env {
139135 fn with < F : FnOnce ( & mut Env ) -> T , T > ( f : F ) -> T {
140136 thread_local ! {
141- static ENV : RefCell <Env > = Default :: default ( ) ;
137+ static ENV : RefCell <Env > = RefCell :: new( Env {
138+ pushd_stack: vec![ env:: current_dir( ) . unwrap( ) ]
139+ } ) ;
142140 }
143141 ENV . with ( |it| f ( & mut * it. borrow_mut ( ) ) )
144142 }
145143
146144 fn pushd ( & mut self , dir : PathBuf ) {
147145 let dir = self . cwd ( ) . join ( dir) ;
148- self . pushd_stack . push ( dir)
146+ self . pushd_stack . push ( dir) ;
147+ env:: set_current_dir ( self . cwd ( ) ) . unwrap ( ) ;
149148 }
150149 fn popd ( & mut self ) {
151150 self . pushd_stack . pop ( ) . unwrap ( ) ;
151+ env:: set_current_dir ( self . cwd ( ) ) . unwrap ( ) ;
152152 }
153- fn cwd ( & self ) -> PathBuf {
154- self . pushd_stack . last ( ) . cloned ( ) . unwrap_or_else ( || env :: current_dir ( ) . unwrap ( ) )
153+ fn cwd ( & self ) -> & Path {
154+ self . pushd_stack . last ( ) . unwrap ( )
155155 }
156156}
0 commit comments