From 899e5845d5d5e3dd8e2560d6eb948c1f308b49c1 Mon Sep 17 00:00:00 2001 From: Martin Nordholts Date: Thu, 25 Apr 2024 06:19:27 +0200 Subject: [PATCH] bootstrap: Avoid `Invalid cross-device link (os error 18)` for downloads When I do src/ci/docker/run.sh --dev armhf-gnu ../x test --target arm-unknown-linux-gnueabihf \ tests/ui/compiletest-self-test/test-aux-bin.rs I get thread 'main' panicked at src/core/download.rs:211:9: std::fs::rename(&tempfile, dest_path) failed with Invalid cross-device link (os error 18) in WSL2. Fix this by downloading the temp file to the same file system as the destination file. --- src/bootstrap/src/core/download.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/bootstrap/src/core/download.rs b/src/bootstrap/src/core/download.rs index 75e0f646da699..13bdb6c031343 100644 --- a/src/bootstrap/src/core/download.rs +++ b/src/bootstrap/src/core/download.rs @@ -197,7 +197,9 @@ impl Config { fn download_file(&self, url: &str, dest_path: &Path, help_on_error: &str) { self.verbose(|| println!("download {url}")); // Use a temporary file in case we crash while downloading, to avoid a corrupt download in cache/. - let tempfile = self.tempdir().join(dest_path.file_name().unwrap()); + // Download to the same directory as the final file to avoid having to move it across file systems. + let mut tempfile = dest_path.to_owned(); + tempfile.set_extension("incomplete-bootstrap-download"); // While bootstrap itself only supports http and https downloads, downstream forks might // need to download components from other protocols. The match allows them adding more // protocols without worrying about merge conflicts if we change the HTTP implementation.