Skip to content

Commit ae66d15

Browse files
authored
Merge pull request #1873 from rbtcollins/bug-1870
Fix #1870: Race condition with some virus scanners
2 parents 500c9a2 + 8d59015 commit ae66d15

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

Cargo.lock

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ wait-timeout = "0.2"
5555
walkdir = "2"
5656
xz2 = "0.1.3"
5757

58+
[dependencies.retry]
59+
version = "0.5"
60+
default-features = false
61+
5862
[target."cfg(windows)".dependencies]
5963
cc = "1"
6064
winreg = "0.6"

src/utils/utils.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ use std::path::{Path, PathBuf};
1111
use std::process::Command;
1212
use url::Url;
1313

14+
use retry::delay::{jitter, Fibonacci};
15+
use retry::{retry, OperationResult};
16+
1417
#[cfg(windows)]
1518
use winapi::shared::minwindef::DWORD;
1619

@@ -651,7 +654,21 @@ pub fn toolchain_sort<T: AsRef<str>>(v: &mut Vec<T>) {
651654
}
652655

653656
fn rename(name: &'static str, src: &Path, dest: &Path) -> Result<()> {
654-
fs::rename(src, dest).chain_err(|| ErrorKind::RenamingFile {
657+
// https://github.com/rust-lang/rustup.rs/issues/1870
658+
// 21 fib steps from 1 sums to ~28 seconds, hopefully more than enough
659+
// for our previous poor performance that avoided the race condition with
660+
// McAfee and Norton.
661+
retry(
662+
Fibonacci::from_millis(1).map(jitter).take(21),
663+
|| match fs::rename(src, dest) {
664+
Ok(v) => OperationResult::Ok(v),
665+
Err(e) => match e.kind() {
666+
io::ErrorKind::PermissionDenied => OperationResult::Retry(e),
667+
_ => OperationResult::Err(e),
668+
},
669+
},
670+
)
671+
.chain_err(|| ErrorKind::RenamingFile {
655672
name,
656673
src: PathBuf::from(src),
657674
dest: PathBuf::from(dest),

0 commit comments

Comments
 (0)