X-Git-Url: https://git.tld-linux.org/?a=blobdiff_plain;f=TLD_Builder%2Fchroot.py;h=3e427b9a38436f88137f4f580a7a7d9e09192e1e;hb=1b7332b1eeedc313bbef96e41ec44925d86cc96d;hp=b790e51dbbad431885d46b3ff2f25d59de526448;hpb=284d49e1cdca63cde4114c123815e9f0b7e8dbdb;p=tld-builder.git diff --git a/TLD_Builder/chroot.py b/TLD_Builder/chroot.py index b790e51..3e427b9 100644 --- a/TLD_Builder/chroot.py +++ b/TLD_Builder/chroot.py @@ -4,11 +4,7 @@ import os import re import random import util - -try: - from hashlib import md5 as md5 -except ImportError: - from md5 import md5 +import subprocess from config import config @@ -54,36 +50,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