diff options
author | Dan Willemsen <dwillemsen@google.com> | 2018-11-15 19:15:02 -0800 |
---|---|---|
committer | Dan Willemsen <dwillemsen@google.com> | 2018-12-03 15:55:15 -0800 |
commit | 263dde779e4e1b04f7b2507162b9d893763e3129 (patch) | |
tree | 66b029d846e1e3b17cb111ed244fc8897060968f /cmd | |
parent | 314d8c142cc135bde537d8849c3644ee753fcb9c (diff) | |
download | build_soong-263dde779e4e1b04f7b2507162b9d893763e3129.tar.gz build_soong-263dde779e4e1b04f7b2507162b9d893763e3129.tar.bz2 build_soong-263dde779e4e1b04f7b2507162b9d893763e3129.zip |
Fix par file zip offsets
The zip file format does support scripts/programs prefixed to the
archive, though many of the offsets are supposed to start from the
beginning of the file. Some tools (python and zipinfo) are able to
read zip files with arbitrary prefixes, but others (libziparchive and
zipdetails) fail.
So pass the file to prefix onto the zip file into merge_zips so that we
can set the offsets from the real start of the file.
Test: m sepolicy_tests (runs the embedded python interpreter)
Test: zipinfo out/host/linux-x86/bin/sepolicy_tests
Test: zipdetails out/host/linux-x86/bin/sepolicy_tests
Change-Id: If73d4c2465581f7de5aa47959284ecf2059df091
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/merge_zips/merge_zips.go | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/cmd/merge_zips/merge_zips.go b/cmd/merge_zips/merge_zips.go index 8e71a978..c21da44b 100644 --- a/cmd/merge_zips/merge_zips.go +++ b/cmd/merge_zips/merge_zips.go @@ -19,6 +19,7 @@ import ( "flag" "fmt" "hash/crc32" + "io" "io/ioutil" "log" "os" @@ -66,6 +67,7 @@ var ( manifest = flag.String("m", "", "manifest file to insert in jar") pyMain = flag.String("pm", "", "__main__.py file to insert in par") entrypoint = flag.String("e", "", "par entrypoint file to insert in par") + prefix = flag.String("prefix", "", "A file to prefix to the zip file") ignoreDuplicates = flag.Bool("ignore-duplicates", false, "take each entry from the first zip it exists in and don't warn") ) @@ -77,7 +79,7 @@ func init() { func main() { flag.Usage = func() { - fmt.Fprintln(os.Stderr, "usage: merge_zips [-jpsD] [-m manifest] [-e entrypoint] [-pm __main__.py] output [inputs...]") + fmt.Fprintln(os.Stderr, "usage: merge_zips [-jpsD] [-m manifest] [--prefix script] [-e entrypoint] [-pm __main__.py] output [inputs...]") flag.PrintDefaults() } @@ -99,6 +101,19 @@ func main() { log.Fatal(err) } defer output.Close() + + var offset int64 + if *prefix != "" { + prefixFile, err := os.Open(*prefix) + if err != nil { + log.Fatal(err) + } + offset, err = io.Copy(output, prefixFile) + if err != nil { + log.Fatal(err) + } + } + writer := zip.NewWriter(output) defer func() { err := writer.Close() @@ -106,6 +121,7 @@ func main() { log.Fatal(err) } }() + writer.SetOffset(offset) // make readers readers := []namedZipReader{} |