in xar/xar_util.py [0:0]
def go(self):
"Make the XAR file."
logger.info("Squashing %s to %s" % (self.dirname, self.output))
if self.uuid is None:
self.uuid = make_uuid()
if self.version is None:
self.version = time.time()
tf = tempfile.NamedTemporaryFile(delete=False)
# Create!
sqopts = self.squashfs_options
cmd = [
sqopts.mksquashfs,
self.dirname,
tf.name,
"-noappend",
"-noI",
"-noX", # is this worth it? probably
"-force-uid",
"nobody",
"-force-gid",
NOGROUP,
"-b",
str(sqopts.block_size),
"-comp",
sqopts.compression_algorithm,
]
if sqopts.compression_algorithm == "zstd":
cmd.extend(("-Xcompression-level", str(sqopts.zstd_level)))
if self.sort_file:
cmd.extend(["-sort", self.sort_file])
if sys.stdout.isatty():
subprocess.check_call(cmd)
else:
with open("/dev/null", "wb") as f:
subprocess.check_call(cmd, stdout=f)
headers = [self.header_prefix]
# Take the squash file, create a header, and write it
with open(self.output, "wb") as of:
# Make a "safe" header that is easily parsed and also not
# going to explode if accidentally executed.
headers.append('OFFSET="$OFFSET"')
headers.append('UUID="$UUID"')
headers.append('VERSION="%d"' % self.version)
for key, val in self.xar_header.items():
headers.append('%s="%s"' % (key, str(val).replace('"', " ")))
headers.append("#xar_stop")
headers.append("echo This XAR file should not be executed by sh")
headers.append("exit 1")
headers.append("# Actual squashfs file begins at $OFFSET")
text_headers = "\n".join(headers) + "\n"
# 128 is to account for expansion of $OFFSET and $UUID;
# it's well over what they might reasonably be.
header_size = _align_offset(128 + len(text_headers))
text_headers = text_headers.replace("$OFFSET", "%d" % header_size)
text_headers = text_headers.replace("$UUID", self.uuid)
text_headers += "\n" * (header_size - len(text_headers))
of.write(text_headers.encode("UTF-8"))
# Now append the squashfs file to the header.
with open(tf.name, "rb") as rf:
while True:
data = rf.read(1024 * 1024)
if not data:
break
of.write(data)