Commit 9cc30ac0 authored by Kevin Marshall's avatar Kevin Marshall Committed by Commit Bot

Fuchsia: Write temporary minfs data files to tmpdir.

This change uses the tempfile library to manage temporary named files
instead of using a DIY try/finally approach.

Bug: 832849
Change-Id: I439ff29edfb0e8791202604d56f891827d79f0a2
Reviewed-on: https://chromium-review.googlesource.com/1029212Reviewed-by: default avatarScott Graham <scottmg@chromium.org>
Commit-Queue: Kevin Marshall <kmarshall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#553908}
parent 14c132c2
...@@ -97,37 +97,34 @@ def ConfigureDataFVM(output_dir, sparse): ...@@ -97,37 +97,34 @@ def ConfigureDataFVM(output_dir, sparse):
Returns the path to the new FVM file.""" Returns the path to the new FVM file."""
logging.debug('Building persistent data FVM file.') logging.debug('Building persistent data FVM file.')
data_file = os.path.join(output_dir, 'data.minfs.bin') data_file = tempfile.NamedTemporaryFile()
try:
# Build up the minfs partition data and install keys into it. # Build up the minfs partition data and install keys into it.
ssh_config, ssh_data = _ProvisionSSH(output_dir) ssh_config, ssh_data = _ProvisionSSH(output_dir)
manifest = tempfile.NamedTemporaryFile() manifest = tempfile.NamedTemporaryFile()
for dest, src in ssh_data: for dest, src in ssh_data:
manifest.write('%s=%s\n' % (dest, src)) manifest.write('%s=%s\n' % (dest, src))
manifest.flush() manifest.flush()
minfs_path = os.path.join(common.SDK_ROOT, 'tools', 'minfs') minfs_path = os.path.join(common.SDK_ROOT, 'tools', 'minfs')
subprocess.check_call([minfs_path, '%s@10m' % data_file, 'create']) subprocess.check_call([minfs_path, '%s@10m' % data_file.name, 'create'])
subprocess.check_call([minfs_path, data_file, 'manifest', manifest.name]) subprocess.check_call([minfs_path, data_file.name, 'manifest', manifest.name])
# Wrap the minfs partition in a FVM container. # Wrap the minfs partition in a FVM container.
fvm_path = os.path.join(common.SDK_ROOT, 'tools', 'fvm') fvm_path = os.path.join(common.SDK_ROOT, 'tools', 'fvm')
fvm_output_path = os.path.join(output_dir, 'fvm.data.blk') fvm_output_path = os.path.join(output_dir, 'fvm.data.blk')
if os.path.exists(fvm_output_path): if os.path.exists(fvm_output_path):
os.remove(fvm_output_path) os.remove(fvm_output_path)
if sparse: if sparse:
cmd = [fvm_path, fvm_output_path, 'sparse', '--compress', 'lz4', cmd = [fvm_path, fvm_output_path, 'sparse', '--compress', 'lz4',
'--data', data_file] '--data', data_file.name]
else: else:
cmd = [fvm_path, fvm_output_path, 'create', '--data', data_file] cmd = [fvm_path, fvm_output_path, 'create', '--data', data_file.name]
logging.debug(' '.join(cmd)) logging.debug(' '.join(cmd))
subprocess.check_call(cmd) subprocess.check_call(cmd)
return fvm_output_path return fvm_output_path
finally:
os.remove(data_file)
def GetNodeName(output_dir): def GetNodeName(output_dir):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment