Rollup merge of #124975 - lu-zero:move_file, r=clubby789

Use an helper to move the files

In case the source is not in the same filesystem.

See c1b3e0440f (commitcomment-141886468)
This commit is contained in:
León Orell Valerian Liehr 2024-05-15 14:21:37 +02:00 committed by GitHub
commit 2e70bea168
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 24 additions and 7 deletions

View file

@ -26,7 +26,9 @@
use crate::core::builder::{Builder, Kind, RunConfig, ShouldRun, Step};
use crate::core::config::TargetSelection;
use crate::utils::channel::{self, Info};
use crate::utils::helpers::{exe, is_dylib, output, t, target_supports_cranelift_backend, timeit};
use crate::utils::helpers::{
exe, is_dylib, move_file, output, t, target_supports_cranelift_backend, timeit,
};
use crate::utils::tarball::{GeneratedTarball, OverlayKind, Tarball};
use crate::{Compiler, DependencyType, Mode, LLVM_TOOLS};
@ -2024,7 +2026,7 @@ fn filter(contents: &str, marker: &str) -> String {
builder.run(&mut cmd);
if !builder.config.dry_run() {
t!(fs::rename(exe.join(&filename), distdir(builder).join(&filename)));
t!(move_file(exe.join(&filename), distdir(builder).join(&filename)));
}
}
}

View file

@ -12,7 +12,7 @@
use build_helper::stage0_parser::VersionMetadata;
use xz2::bufread::XzDecoder;
use crate::utils::helpers::{check_run, exe, program_out_of_date};
use crate::utils::helpers::{check_run, exe, move_file, program_out_of_date};
use crate::{core::build_steps::llvm::detect_llvm_sha, utils::helpers::hex_encode};
use crate::{t, Config};
@ -209,7 +209,7 @@ fn download_file(&self, url: &str, dest_path: &Path, help_on_error: &str) {
None => panic!("no protocol in {url}"),
}
t!(
std::fs::rename(&tempfile, dest_path),
move_file(&tempfile, dest_path),
format!("failed to rename {tempfile:?} to {dest_path:?}")
);
}
@ -313,7 +313,7 @@ fn unpack(&self, tarball: &Path, dst: &Path, pattern: &str) {
if src_path.is_dir() && dst_path.exists() {
continue;
}
t!(fs::rename(src_path, dst_path));
t!(move_file(src_path, dst_path));
}
let dst_dir = dst.join(directory_prefix);
if dst_dir.exists() {

View file

@ -150,6 +150,21 @@ fn symlink_dir_inner(target: &Path, junction: &Path) -> io::Result<()> {
}
}
/// Rename a file if from and to are in the same filesystem or
/// copy and remove the file otherwise
pub fn move_file<P: AsRef<Path>, Q: AsRef<Path>>(from: P, to: Q) -> io::Result<()> {
match fs::rename(&from, &to) {
// FIXME: Once `ErrorKind::CrossesDevices` is stabilized use
// if e.kind() == io::ErrorKind::CrossesDevices {
#[cfg(unix)]
Err(e) if e.raw_os_error() == Some(libc::EXDEV) => {
std::fs::copy(&from, &to)?;
std::fs::remove_file(&from)
}
r => r,
}
}
pub fn forcing_clang_based_tests() -> bool {
if let Some(var) = env::var_os("RUSTBUILD_FORCE_CLANG_BASED_TESTS") {
match &var.to_string_lossy().to_lowercase()[..] {

View file

@ -13,7 +13,7 @@
use crate::core::builder::Builder;
use crate::core::{build_steps::dist::distdir, builder::Kind};
use crate::utils::channel;
use crate::utils::helpers::t;
use crate::utils::helpers::{move_file, t};
#[derive(Copy, Clone)]
pub(crate) enum OverlayKind {
@ -284,7 +284,7 @@ pub(crate) fn bare(self) -> GeneratedTarball {
// name, not "image". We rename the image directory just before passing
// into rust-installer.
let dest = self.temp_dir.join(self.package_name());
t!(std::fs::rename(&self.image_dir, &dest));
t!(move_file(&self.image_dir, &dest));
self.run(|this, cmd| {
let distdir = distdir(this.builder);