mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-08-03 12:44:22 -07:00
Modified assemble module so the dest file is streamed together rather than built-in memory before writing.
This commit is contained in:
parent
1f8d319753
commit
3e774fedea
1 changed files with 10 additions and 14 deletions
|
@ -67,22 +67,18 @@ author: Stephen Fromm
|
||||||
'''
|
'''
|
||||||
|
|
||||||
# ===========================================
|
# ===========================================
|
||||||
# Support methods
|
# Support method
|
||||||
|
|
||||||
def assemble_from_fragments(path):
|
def assemble_from_fragments(src_path):
|
||||||
''' assemble a file from a directory of fragments '''
|
''' assemble a file from a directory of fragments '''
|
||||||
assembled = []
|
tmpfd, temp_path = tempfile.mkstemp()
|
||||||
for f in sorted(os.listdir(path)):
|
tmp = os.fdopen(tmpfd,'w')
|
||||||
fragment = "%s/%s" % (path, f)
|
for f in sorted(os.listdir(src_path)):
|
||||||
|
fragment = "%s/%s" % (src_path, f)
|
||||||
if os.path.isfile(fragment):
|
if os.path.isfile(fragment):
|
||||||
assembled.append(file(fragment).read())
|
tmp.write(file(fragment).read())
|
||||||
return "".join(assembled)
|
tmp.close()
|
||||||
|
return temp_path
|
||||||
def write_temp_file(data):
|
|
||||||
fd, path = tempfile.mkstemp()
|
|
||||||
os.write(fd, data)
|
|
||||||
os.close(fd)
|
|
||||||
return path
|
|
||||||
|
|
||||||
# ==============================================================
|
# ==============================================================
|
||||||
# main
|
# main
|
||||||
|
@ -112,7 +108,7 @@ def main():
|
||||||
if not os.path.isdir(src):
|
if not os.path.isdir(src):
|
||||||
module.fail_json(msg="Source (%s) is not a directory" % src)
|
module.fail_json(msg="Source (%s) is not a directory" % src)
|
||||||
|
|
||||||
path = write_temp_file(assemble_from_fragments(src))
|
path = assemble_from_fragments(src)
|
||||||
pathmd5 = module.md5(path)
|
pathmd5 = module.md5(path)
|
||||||
|
|
||||||
if os.path.exists(dest):
|
if os.path.exists(dest):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue