Repository: a-scie/jump (rust)

Issue:
`SCIE=split` fails for scie-tote / files with a non-scie `"source"`.
For example, trying to split a [scie-pants scie](https://github.com/pantsbuild/scie-pants/releases) nets:
```
$ SCIE=split scie-pants /tmp/scie-pants-split
Error: Failed to open scie-tote zip: invalid Zip archive: Invalid zip header
$ ls -l /tmp/scie-pants-split/
total 7280
-rw-r--r-- 1 jsirois jsirois       0 Dec 19 12:27 cpython-3.8.15+20221106-aarch64-apple-darwin-install_only.tar.gz
-rw-r--r-- 1 jsirois jsirois 5780260 Dec 19 12:27 cpython-3.8.15+20221106-aarch64-unknown-linux-gnu-install_only.tar.gz
-rw-r--r-- 1 jsirois jsirois       0 Dec 19 12:27 cpython-3.8.15+20221106-x86_64-apple-darwin-install_only.tar.gz
-rw-r--r-- 1 jsirois jsirois       0 Dec 19 12:27 cpython-3.8.15+20221106-x86_64-unknown-linux-gnu-install_only.tar.gz
-rw-r--r-- 1 jsirois jsirois       0 Dec 19 12:27 cpython-3.9.15+20221106-aarch64-apple-darwin-install_only.tar.gz
-rw-r--r-- 1 jsirois jsirois       0 Dec 19 12:27 cpython-3.9.15+20221106-aarch64-unknown-linux-gnu-install_only.tar.gz
-rw-r--r-- 1 jsirois jsirois       0 Dec 19 12:27 cpython-3.9.15+20221106-x86_64-apple-darwin-install_only.tar.gz
-rw-r--r-- 1 jsirois jsirois       0 Dec 19 12:27 cpython-3.9.15+20221106-x86_64-unknown-linux-gnu-install_only.tar.gz
-rwxr-xr-x 1 jsirois jsirois 1668304 Dec 19 12:27 scie-jump
```


Pull request:
Fix SCIE=split to work with ptex.
Previousy, splitting a gouged out scie failed; now it round-trips byte-wise identical.

Fixes #62

Patch:
diff --git a/src/boot/split.rs b/src/boot/split.rs
index 49e031b..88e7c33 100644
--- a/src/boot/split.rs
+++ b/src/boot/split.rs
@@ -7,7 +7,7 @@ use std::io::Read;
 use std::path::{Path, PathBuf};
 
 use jump::config::{FileType, Fmt};
-use jump::{File, Jump, Lift};
+use jump::{File, Jump, Lift, Source};
 use log::debug;
 use proc_exit::{Code, Exit, ExitResult};
 use zip::ZipArchive;
@@ -88,7 +88,9 @@ pub(crate) fn split(jump: Jump, mut lift: Lift, scie_path: PathBuf) -> ExitResul
     let mut scie_tote = vec![];
     let scie_tote_index = lift.files.len() - 1;
     for (index, file) in lift.files.iter().enumerate() {
-        if file.size == 0 {
+        if file.source != Source::Scie {
+            continue;
+        } else if file.size == 0 {
             scie_tote.push(file);
         } else if file.file_type == FileType::Directory
             || (index == scie_tote_index && !scie_tote.is_empty())
@@ -154,13 +156,15 @@ pub(crate) fn split(jump: Jump, mut lift: Lift, scie_path: PathBuf) -> ExitResul
     if !scie_tote.is_empty() {
         lift.files.remove(lift.files.len() - 1);
         for mut file in lift.files.iter_mut() {
-            let metadata = base.join(&file.name).metadata().map_err(|e| {
-                Code::FAILURE.with_message(format!(
-                    "Failed to determine size of {file}: {e}",
-                    file = file.name
-                ))
-            })?;
-            file.size = metadata.len() as usize;
+            if file.source == Source::Scie {
+                let metadata = base.join(&file.name).metadata().map_err(|e| {
+                    Code::FAILURE.with_message(format!(
+                        "Failed to determine size of {file}: {e}",
+                        file = file.name
+                    ))
+                })?;
+                file.size = metadata.len() as usize;
+            }
         }
     }
 


Test patch:
diff --git a/examples/ptex/test.sh b/examples/ptex/test.sh
index 1837a6b..8629caa 100644
--- a/examples/ptex/test.sh
+++ b/examples/ptex/test.sh
@@ -10,6 +10,16 @@ check_cmd mktemp
 gc "${PWD}/cowsay"
 "${SCIE_JUMP}" "${LIFT}"
 
+# Verify byte-wise identical pack -> split -> pack round tripping.
+gc "${PWD}/split"
+SCIE="split" ./cowsay split
+
+sha256 cowsay* > split/cowsay.sha256
+cd split && ./scie-jump
+sha256 --check cowsay.sha256
+sha256 cowsay* ../cowsay*
+cd .. && rm -rf split
+
 # Force downloads to occur to exercise the load functionality even if nce cache has the JDK and the
 # cowsay jars already from other examples.
 SCIE_BASE="$(mktemp -d)"