X-Git-Url: https://git.tld-linux.org/?a=blobdiff_plain;f=TLD_Builder%2Fchroot.py;h=7485e7213add7996c1d4c08f84e7ce0f216d9356;hb=bc5e1af0e1a33e54f39a5a93c8aa7aae4ef74cd8;hp=b790e51dbbad431885d46b3ff2f25d59de526448;hpb=284d49e1cdca63cde4114c123815e9f0b7e8dbdb;p=tld-builder.git diff --git a/TLD_Builder/chroot.py b/TLD_Builder/chroot.py index b790e51..7485e72 100644 --- a/TLD_Builder/chroot.py +++ b/TLD_Builder/chroot.py @@ -4,11 +4,8 @@ import os import re import random import util - -try: - from hashlib import md5 as md5 -except ImportError: - from md5 import md5 +import shutil +import subprocess from config import config @@ -54,36 +51,16 @@ def run(cmd, user = "builder", logfile = None, logstdout = None): return r def cp(file, outfile, user="builder", rm=False): - m = md5() - m.update(util.to_bytes(str(random.sample(range(100000), 500)))) - digest = m.hexdigest() - - marker_start = "--- FILE BEGIN DIGEST %s ---" % digest - marker_end = "--- FILE END DIGEST %s ---" % digest - - f = open(outfile, 'wb') - cmd = "echo \"%s\"; cat %s; echo \"%s\"" % (marker_start, file, marker_end) + f_out = open(outfile, 'wb') + cmd = "cat %s" % file if rm: cmd += "; rm %s" % file - c = command(cmd, user) - p = os.popen(c) - # get file contents - marker = False - for l in p: - if not marker and l.strip() == marker_start: - marker = True - continue - me = l.find(marker_end) - if me != -1: - l = l[:me] - f.write(util.to_bytes(l)) - marker = False - break - if marker: - f.write(util.to_bytes(l)) - rp = p.close() - rf = f.close() - if rp == None: + p = subprocess.Popen(command(cmd, user), shell=True, stdout=subprocess.PIPE, close_fds=True) + f_in = p.stdout + shutil.copyfileobj(f_in, f_out) + f_out.close() + r = f_in.close() + if r == None: return 0 else: - return rp + return r