@@ -95,15 +95,15 @@ where
9595/// Returns the available space in MB, or None if the check fails.
9696pub fn get_available_disk_space_mb ( path : & Path ) -> Option < u64 > {
9797 use sysinfo:: Disks ;
98-
98+
9999 // Find the disk that contains the given path
100100 let path_canonical = match std:: fs:: canonicalize ( path) {
101101 Ok ( p) => p,
102102 Err ( _) => return None ,
103103 } ;
104-
104+
105105 let disks = Disks :: new_with_refreshed_list ( ) ;
106-
106+
107107 // Find the disk that contains the given path
108108 for disk in disks. iter ( ) {
109109 let mount_point = disk. mount_point ( ) ;
@@ -113,7 +113,7 @@ pub fn get_available_disk_space_mb(path: &Path) -> Option<u64> {
113113 return Some ( available_bytes / ( 1024 * 1024 ) ) ;
114114 }
115115 }
116-
116+
117117 None
118118}
119119
@@ -169,7 +169,7 @@ mod tests {
169169 // and returns a boolean value
170170 let temp_dir = std:: env:: temp_dir ( ) ;
171171 let result = is_disk_space_low ( & temp_dir, 1_000_000_000 ) ; // Very large threshold
172- // Should return either true or false, but not panic
172+ // Should return either true or false, but not panic
173173 assert ! ( result == true || result == false ) ;
174174 }
175175
@@ -213,20 +213,29 @@ mod tests {
213213 fn test_is_disk_space_low_threshold_comparison ( ) {
214214 // Test that the function correctly compares available space with threshold
215215 let temp_dir = std:: env:: temp_dir ( ) ;
216-
216+
217217 if let Some ( available_mb) = get_available_disk_space_mb ( & temp_dir) {
218- // Test with a threshold smaller than available space (should pass - space is sufficient)
218+ // Test with a threshold smaller than available space (should pass - space is
219+ // sufficient)
219220 if available_mb > 0 {
220221 let result_small = is_disk_space_low ( & temp_dir, available_mb. saturating_sub ( 1 ) ) ;
221- assert ! ( !result_small, "Should pass (return false) when threshold is less than available space" ) ;
222+ assert ! (
223+ !result_small,
224+ "Should pass (return false) when threshold is less than available space"
225+ ) ;
222226 }
223-
224- // Test with a threshold larger than available space (should fail - space is insufficient)
227+
228+ // Test with a threshold larger than available space (should fail - space is
229+ // insufficient)
225230 let result_large = is_disk_space_low ( & temp_dir, available_mb. saturating_add ( 1 ) ) ;
226- assert ! ( result_large, "Should fail (return true) when threshold is greater than available space" ) ;
227-
231+ assert ! (
232+ result_large,
233+ "Should fail (return true) when threshold is greater than available space"
234+ ) ;
235+
228236 // Test with threshold equal to available space (edge case)
229- // When available == threshold, should trigger shutdown (return true) because "once reached" includes equality
237+ // When available == threshold, should trigger shutdown (return true) because "once
238+ // reached" includes equality
230239 let result_equal = is_disk_space_low ( & temp_dir, available_mb) ;
231240 assert ! ( result_equal, "Should fail (return true) when threshold equals available space, as 'once reached' includes equality" ) ;
232241 }
0 commit comments