diff --git a/tests/integration.rs b/tests/integration.rs index 9f30809cd..1c0931278 100644 --- a/tests/integration.rs +++ b/tests/integration.rs @@ -116,11 +116,33 @@ mod tests { } fn rate_limited_copy, Q: AsRef>(from: P, to: Q) -> io::Result { - for _ in 0..10 { + for i in 0..10 { + let free_bytes = unsafe { + let mut stats = std::mem::MaybeUninit::zeroed(); + let fs_name = std::ffi::CString::new("/tmp").unwrap(); + libc::statvfs(fs_name.as_ptr(), stats.as_mut_ptr()); + + let free_blocks = stats.assume_init().f_bfree; + let block_size = stats.assume_init().f_bsize; + + free_blocks * block_size + }; + + // Make sure there is at least 6 GiB of space + if free_bytes < 6 << 30 { + eprintln!( + "Not enough space on disk ({}). Attempt {} of 10. Sleeping.", + free_bytes, i + ); + thread::sleep(std::time::Duration::new(60, 0)); + continue; + } + match fs::copy(&from, &to) { Err(e) => { if let Some(errno) = e.raw_os_error() { if errno == libc::ENOSPC { + eprintln!("Copy returned ENOSPC. Attempt {} of 10. Sleeping.", i); thread::sleep(std::time::Duration::new(60, 0)); continue; }