diff options
author | Mitchell Wills <mwills@google.com> | 2019-11-08 15:08:59 -0800 |
---|---|---|
committer | Mitchell Wills <mwills@google.com> | 2019-11-11 11:18:26 -0800 |
commit | 855bf6a85bb70f619112981368ed79f677658acb (patch) | |
tree | 2b6941bc916d394440c01a65f71e3f224cc33e1c /tools/generate-self-extracting-archive.py | |
parent | 6cbbac5cec9bff648a6acfd1cec3e1adb55242f2 (diff) |
[generate-self-extracting-archive] Cleanup and improve error handling
Increase the max extract offset and add some input sanity checks
Make the output file executable
Test: Ran manually with various license inputs
Bug: 125451157
Change-Id: Id76d55479366f1d9b8906e6d04c1a6db8d4d8285
Diffstat (limited to 'tools/generate-self-extracting-archive.py')
-rwxr-xr-x | tools/generate-self-extracting-archive.py | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/tools/generate-self-extracting-archive.py b/tools/generate-self-extracting-archive.py index f0b7568116..5a193ab8ec 100755 --- a/tools/generate-self-extracting-archive.py +++ b/tools/generate-self-extracting-archive.py @@ -91,7 +91,7 @@ def _pipe_bytes(src, dst): break dst.write(b) -_MAX_OFFSET_WIDTH = 8 +_MAX_OFFSET_WIDTH = 20 def _generate_extract_command(start, end, extract_name): """Generate the extract command. @@ -119,6 +119,10 @@ def _generate_extract_command(start, end, extract_name): def main(argv): + if len(argv) != 5: + print 'generate-self-extracting-archive.py expects exactly 4 arguments' + sys.exit(1) + output_filename = argv[1] input_archive_filename = argv[2] comment = argv[3] @@ -129,6 +133,14 @@ def main(argv): with open(license_filename, 'r') as license_file: license = license_file.read() + if not license: + print 'License file was empty' + sys.exit(1) + + if 'SOFTWARE LICENSE AGREEMENT' not in license: + print 'License does not look like a license' + sys.exit(1) + comment_line = '# %s\n' % comment extract_name = os.path.basename(input_archive_filename) @@ -161,5 +173,9 @@ def main(argv): trailing_zip.seek(0) _pipe_bytes(trailing_zip, output) + umask = os.umask(0) + os.umask(umask) + os.chmod(output_filename, 0o777 & ~umask) + if __name__ == "__main__": main(sys.argv) |