@@ -7,15 +7,13 @@ use crate::runner::{OverrideResult, RunnerState};
77use crate :: utils;
88use rustwide:: { BuildDirectory , Workspace } ;
99use std:: collections:: HashMap ;
10- use std:: path:: Path ;
1110use std:: sync:: {
1211 atomic:: { AtomicBool , Ordering } ,
1312 mpsc:: { self , RecvTimeoutError } ,
1413 Arc , Mutex ,
1514} ;
1615use std:: thread;
1716use std:: time:: Duration ;
18- use systemstat:: { Filesystem , Platform , System } ;
1917
2018pub ( super ) struct Worker < ' a , DB : WriteResults + Sync > {
2119 name : String ,
@@ -185,54 +183,21 @@ impl<'a, DB: WriteResults + Sync> DiskSpaceWatcher<'a, DB> {
185183 }
186184
187185 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 ) => {
191189 // 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 ) ;
193191 return Ok ( ( ) ) ;
194192 }
195193 } ;
196194
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" ) ;
212197 for worker in self . workers {
213198 worker. schedule_target_dir_cleanup ( ) ;
214199 }
215- warn ! ( "scheduled cleanup" ) ;
216200 }
217201 Ok ( ( ) )
218202 }
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- }
238203}
0 commit comments