@@ -71,10 +71,6 @@ pub fn pushd(path: impl Into<PathBuf>) -> Pushd {
71
71
Pushd { _p : ( ) }
72
72
}
73
73
74
- pub fn pwd ( ) -> PathBuf {
75
- Env :: with ( |env| env. cwd ( ) )
76
- }
77
-
78
74
impl Drop for Pushd {
79
75
fn drop ( & mut self ) {
80
76
Env :: with ( |env| env. popd ( ) )
@@ -101,14 +97,15 @@ pub fn run_process(cmd: String, echo: bool) -> Result<String> {
101
97
fn run_process_inner ( cmd : & str , echo : bool ) -> Result < String > {
102
98
let mut args = shelx ( cmd) ;
103
99
let binary = args. remove ( 0 ) ;
100
+ let current_dir = Env :: with ( |it| it. cwd ( ) . to_path_buf ( ) ) ;
104
101
105
102
if echo {
106
103
println ! ( "> {}" , cmd)
107
104
}
108
105
109
106
let output = Command :: new ( binary)
110
107
. args ( args)
111
- . current_dir ( pwd ( ) )
108
+ . current_dir ( current_dir )
112
109
. stdin ( Stdio :: null ( ) )
113
110
. stderr ( Stdio :: inherit ( ) )
114
111
. output ( ) ?;
@@ -130,27 +127,30 @@ fn shelx(cmd: &str) -> Vec<String> {
130
127
cmd. split_whitespace ( ) . map ( |it| it. to_string ( ) ) . collect ( )
131
128
}
132
129
133
- #[ derive( Default ) ]
134
130
struct Env {
135
131
pushd_stack : Vec < PathBuf > ,
136
132
}
137
133
138
134
impl Env {
139
135
fn with < F : FnOnce ( & mut Env ) -> T , T > ( f : F ) -> T {
140
136
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
+ } ) ;
142
140
}
143
141
ENV . with ( |it| f ( & mut * it. borrow_mut ( ) ) )
144
142
}
145
143
146
144
fn pushd ( & mut self , dir : PathBuf ) {
147
145
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 ( ) ;
149
148
}
150
149
fn popd ( & mut self ) {
151
150
self . pushd_stack . pop ( ) . unwrap ( ) ;
151
+ env:: set_current_dir ( self . cwd ( ) ) . unwrap ( ) ;
152
152
}
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 ( )
155
155
}
156
156
}
0 commit comments