Skip to content

Commit 5a15d85

Browse files
authored
Don't preserve V8 archive mode and ownership on build (#1244)
By default, copying a file will preserve its mode and ownership attributes. This is an issue when copying the V8 archive from a read-only filesystem since the archive file also becomes read-only, so subsequent builds will fail. We now create a new destination file and copy the content of the archive to it, this ensures the destination file has the default attributes.
1 parent 6cc61a2 commit 5a15d85

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

build.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use fslock::LockFile;
33
use std::collections::HashSet;
44
use std::env;
55
use std::fs;
6+
use std::io;
67
use std::path::Path;
78
use std::path::PathBuf;
89
use std::process::exit;
@@ -383,7 +384,7 @@ fn build_dir() -> PathBuf {
383384

384385
fn download_file(url: String, filename: PathBuf) {
385386
if !url.starts_with("http:") && !url.starts_with("https:") {
386-
fs::copy(&url, filename).unwrap();
387+
copy_archive(&url, &filename);
387388
return;
388389
}
389390

@@ -455,6 +456,19 @@ fn download_static_lib_binaries() {
455456
download_file(url, static_lib_path());
456457
}
457458

459+
/// Copy the V8 archive at `url` to `filename`.
460+
///
461+
/// This function doesn't use `std::fs::copy` because that would
462+
/// preveserve the file attributes such as ownership and mode flags.
463+
/// Instead, it copies the file contents to a new file.
464+
/// This is necessary because the V8 archive could live inside a read-only
465+
/// filesystem, and subsequent builds would fail to overwrite it.
466+
fn copy_archive(url: &str, filename: &Path) {
467+
let mut src = fs::File::open(url).unwrap();
468+
let mut dst = fs::File::create(filename).unwrap();
469+
io::copy(&mut src, &mut dst).unwrap();
470+
}
471+
458472
fn print_link_flags() {
459473
println!("cargo:rustc-link-lib=static=rusty_v8");
460474

0 commit comments

Comments
 (0)