mirror of
https://github.com/denoland/rusty_v8.git
synced 2024-11-21 15:04:33 -05:00
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.
This commit is contained in:
parent
6cc61a26b2
commit
5a15d85f2f
1 changed files with 15 additions and 1 deletions
16
build.rs
16
build.rs
|
@ -3,6 +3,7 @@ use fslock::LockFile;
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
|
use std::io;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::process::exit;
|
use std::process::exit;
|
||||||
|
@ -383,7 +384,7 @@ fn build_dir() -> PathBuf {
|
||||||
|
|
||||||
fn download_file(url: String, filename: PathBuf) {
|
fn download_file(url: String, filename: PathBuf) {
|
||||||
if !url.starts_with("http:") && !url.starts_with("https:") {
|
if !url.starts_with("http:") && !url.starts_with("https:") {
|
||||||
fs::copy(&url, filename).unwrap();
|
copy_archive(&url, &filename);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -455,6 +456,19 @@ fn download_static_lib_binaries() {
|
||||||
download_file(url, static_lib_path());
|
download_file(url, static_lib_path());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Copy the V8 archive at `url` to `filename`.
|
||||||
|
///
|
||||||
|
/// This function doesn't use `std::fs::copy` because that would
|
||||||
|
/// preveserve the file attributes such as ownership and mode flags.
|
||||||
|
/// Instead, it copies the file contents to a new file.
|
||||||
|
/// This is necessary because the V8 archive could live inside a read-only
|
||||||
|
/// filesystem, and subsequent builds would fail to overwrite it.
|
||||||
|
fn copy_archive(url: &str, filename: &Path) {
|
||||||
|
let mut src = fs::File::open(url).unwrap();
|
||||||
|
let mut dst = fs::File::create(filename).unwrap();
|
||||||
|
io::copy(&mut src, &mut dst).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
fn print_link_flags() {
|
fn print_link_flags() {
|
||||||
println!("cargo:rustc-link-lib=static=rusty_v8");
|
println!("cargo:rustc-link-lib=static=rusty_v8");
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue