@@ -7,15 +7,13 @@ use crate::runner::{OverrideResult, RunnerState};
7
7
use crate :: utils;
8
8
use rustwide:: { BuildDirectory , Workspace } ;
9
9
use std:: collections:: HashMap ;
10
- use std:: path:: Path ;
11
10
use std:: sync:: {
12
11
atomic:: { AtomicBool , Ordering } ,
13
12
mpsc:: { self , RecvTimeoutError } ,
14
13
Arc , Mutex ,
15
14
} ;
16
15
use std:: thread;
17
16
use std:: time:: Duration ;
18
- use systemstat:: { Filesystem , Platform , System } ;
19
17
20
18
pub ( super ) struct Worker < ' a , DB : WriteResults + Sync > {
21
19
name : String ,
@@ -185,54 +183,21 @@ impl<'a, DB: WriteResults + Sync> DiskSpaceWatcher<'a, DB> {
185
183
}
186
184
187
185
fn check ( & self ) -> Fallible < ( ) > {
188
- let fs = match self . current_mount ( ) {
189
- Ok ( fs ) => fs ,
190
- Err ( e ) => {
186
+ let usage = match crate :: utils :: disk_usage :: DiskUsage :: fetch ( ) {
187
+ Ok ( usage ) => usage ,
188
+ Err ( err ) => {
191
189
// TODO: `current_mount` fails sometimes on Windows with ERROR_DEVICE_NOT_READY.
192
- warn ! ( "Failed to check space remaining: {}" , e ) ;
190
+ warn ! ( "Failed to check space remaining: {}" , err ) ;
193
191
return Ok ( ( ) ) ;
194
192
}
195
193
} ;
196
194
197
- let usage = ( fs. total . as_usize ( ) - fs. free . as_usize ( ) ) as f32 / fs. total . as_usize ( ) as f32 ;
198
- if usage < self . threshold {
199
- info ! (
200
- "{} disk usage at {}%" ,
201
- fs. fs_mounted_on,
202
- ( usage * 100.0 ) as u8
203
- ) ;
204
- } else {
205
- warn ! (
206
- "{} disk usage at {}%, which is over the threshold of {}%" ,
207
- fs. fs_mounted_on,
208
- ( usage * 100.0 ) as u8 ,
209
- ( self . threshold * 100.0 ) as u8 ,
210
- ) ;
211
-
195
+ if usage. is_threshold_reached ( self . threshold ) {
196
+ warn ! ( "running the scheduled thread cleanup" ) ;
212
197
for worker in self . workers {
213
198
worker. schedule_target_dir_cleanup ( ) ;
214
199
}
215
- warn ! ( "scheduled cleanup" ) ;
216
200
}
217
201
Ok ( ( ) )
218
202
}
219
-
220
- fn current_mount ( & self ) -> Fallible < Filesystem > {
221
- let current_dir = crate :: utils:: path:: normalize_path ( & crate :: dirs:: WORK_DIR ) ;
222
- let system = System :: new ( ) ;
223
-
224
- let mut found = None ;
225
- let mut found_pos = std:: usize:: MAX ;
226
- for mount in system. mounts ( ) ?. into_iter ( ) {
227
- let path = Path :: new ( & mount. fs_mounted_on ) ;
228
- for ( i, ancestor) in current_dir. ancestors ( ) . enumerate ( ) {
229
- if ancestor == path && i < found_pos {
230
- found_pos = i;
231
- found = Some ( mount) ;
232
- break ;
233
- }
234
- }
235
- }
236
- found. ok_or_else ( || failure:: err_msg ( "failed to find the current mount" ) )
237
- }
238
203
}
0 commit comments