Cleanup imgutil open files and processes
Because of the way that compress pipes things between processes it would leave open file descriptors, and running processes around for a bit. This waits for them to exit and closes the fds before returning.
This commit is contained in:
parent
f1aee05167
commit
c3c3605b70
@ -77,9 +77,20 @@ def compress(command, root, outfile, compression="xz", compressargs=None):
|
|||||||
archive.stdin.write(os.path.basename(root).encode("utf-8") + b"\0")
|
archive.stdin.write(os.path.basename(root).encode("utf-8") + b"\0")
|
||||||
archive.stdin.close()
|
archive.stdin.close()
|
||||||
|
|
||||||
comp = Popen([compression] + compressargs,
|
with open(outfile, "wb") as fout:
|
||||||
stdin=archive.stdout, stdout=open(outfile, "wb"))
|
comp = Popen([compression] + compressargs,
|
||||||
comp.wait()
|
stdin=archive.stdout, stdout=fout)
|
||||||
|
comp.wait()
|
||||||
|
|
||||||
|
# Clean up the open fds and processes
|
||||||
|
if find:
|
||||||
|
find.wait()
|
||||||
|
find.stdout.close()
|
||||||
|
archive.wait()
|
||||||
|
if archive.stdin:
|
||||||
|
archive.stdin.close()
|
||||||
|
if archive.stdout:
|
||||||
|
archive.stdout.close()
|
||||||
return comp.returncode
|
return comp.returncode
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
logger.error(e)
|
logger.error(e)
|
||||||
@ -129,8 +140,8 @@ def mkrootfsimg(rootdir, outfile, label, size=2, sysroot=""):
|
|||||||
|
|
||||||
def mksparse(outfile, size):
|
def mksparse(outfile, size):
|
||||||
'''use os.ftruncate to create a sparse file of the given size.'''
|
'''use os.ftruncate to create a sparse file of the given size.'''
|
||||||
fobj = open(outfile, "w")
|
with open(outfile, "w") as fobj:
|
||||||
os.ftruncate(fobj.fileno(), size)
|
os.ftruncate(fobj.fileno(), size)
|
||||||
|
|
||||||
def mkqcow2(outfile, size, options=None):
|
def mkqcow2(outfile, size, options=None):
|
||||||
'''use qemu-img to create a file of the given size.
|
'''use qemu-img to create a file of the given size.
|
||||||
|
Loading…
Reference in New Issue
Block a user