Skip to content

Commit

Permalink
Fix linux installation for newer Unity versions (#387)
Browse files Browse the repository at this point in the history
Description
============

It seems a very old bug suddenly surfaced.
The linux pkg install logic is reading the contents of the archive
into memory and passing it down to the stdin for the `cpio` command.
I used the singe `write` call to copy the `buffer` to the `stdin` without
checking if all bytes are actually written. It seems pure luck that this
worked until now. It seems that in recent versions of Unity some packages
got so big that a single call to `write` wasn't writing all the bytes into the
memory location.

I replaced the logic with a filestream copy instead. Something I should have done
to begin with ...
  • Loading branch information
Larusso committed Dec 11, 2023
1 parent 715590c commit aeada01
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions install/uvm_install_core/src/sys/linux/pkg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::*;
use std::ffi::OsStr;
use std::fs::DirBuilder;
use std::io::Read;
use std::io::Write;
use std::io::{self, BufRead, BufReader, Write};
use std::path::Path;
use std::process::{Command, Stdio};

Expand Down Expand Up @@ -61,11 +61,10 @@ impl ModulePkgInstaller {
.stdin(Stdio::piped())
.spawn()?;
{
let stdin = cpio.stdin.as_mut().expect("stdin");
let stdin = cpio.stdin.as_mut().ok_or("Failed to open cpio stdin")?;
let mut file = File::open(payload)?;
let mut buffer = Vec::new();
file.read_to_end(&mut buffer)?;
stdin.write(&buffer)?;
let mut reader = BufReader::new(file);
io::copy(&mut reader, stdin)?;
}
cpio
} else {
Expand All @@ -81,15 +80,14 @@ impl ModulePkgInstaller {
.stdin(Stdio::piped())
.spawn()?;
{
let stdin = cpio.stdin.as_mut().expect("stdin");
let gzip_std_out = gzip.stdout.as_mut().expect("stdout");
let mut buffer = Vec::new();
gzip_std_out.read_to_end(&mut buffer)?;
stdin.write(&buffer)?;
let gzip_stdout = gzip.stdout.as_mut().ok_or("Failed to open gzip stdout")?;
let cpio_stdin = cpio.stdin.as_mut().ok_or("Failed to open cpio stdin")?;

io::copy(gzip_stdout, cpio_stdin)?;
}
cpio
};

let tar_output = tar_child.wait_with_output()?;
if !tar_output.status.success() {
return Err(format!(
Expand Down

0 comments on commit aeada01

Please sign in to comment.