Skip to content

Commit 0af3030

Browse files
committed
Retry file deletion
1 parent 989de7c commit 0af3030

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/utils/utils.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,22 @@ where
376376
}
377377

378378
pub fn remove_file(name: &'static str, path: &Path) -> Result<()> {
379-
fs::remove_file(path).chain_err(|| ErrorKind::RemovingFile {
379+
// Most files we go to remove won't ever be in use. Some, like proxies, may
380+
// be for indefinite periods, and this will mean we are slower to error and
381+
// have the user fix the issue. Others, like the setup binary, are
382+
// transiently in use, and this wait loop will fix the issue transparently
383+
// for a rare performance hit.
384+
retry(
385+
Fibonacci::from_millis(1).map(jitter).take(10),
386+
|| match fs::remove_file(path) {
387+
Ok(()) => OperationResult::Ok(()),
388+
Err(e) => match e.kind() {
389+
io::ErrorKind::PermissionDenied => OperationResult::Retry(e),
390+
_ => OperationResult::Err(e),
391+
},
392+
},
393+
)
394+
.chain_err(|| ErrorKind::RemovingFile {
380395
name,
381396
path: PathBuf::from(path),
382397
})

0 commit comments

Comments
 (0)