diff --git a/files/assemble b/files/assemble index b7d6c38a04d..7f0a9d1e0a1 100644 --- a/files/assemble +++ b/files/assemble @@ -102,17 +102,22 @@ def assemble_from_fragments(src_path, delimiter=None, compiled_regexp=None): tmpfd, temp_path = tempfile.mkstemp() tmp = os.fdopen(tmpfd,'w') delimit_me = False + add_newline = False for f in sorted(os.listdir(src_path)): if compiled_regexp and not compiled_regexp.search(f): continue fragment = "%s/%s" % (src_path, f) + if not os.path.isfile(fragment): + continue + fragment_content = file(fragment).read() - # delimiters should only appear between fragments - if delimit_me: - # always put a newline between fragments + # always put a newline between fragments if the previous fragment didn't end with a newline. + if add_newline: tmp.write('\n') + # delimiters should only appear between fragments + if delimit_me: if delimiter: # un-escape anything like newlines delimiter = delimiter.decode('unicode-escape') @@ -122,9 +127,12 @@ def assemble_from_fragments(src_path, delimiter=None, compiled_regexp=None): if delimiter[-1] != '\n': tmp.write('\n') - if os.path.isfile(fragment): - tmp.write(file(fragment).read()) + tmp.write(fragment_content) delimit_me = True + if fragment_content.endswith('\n'): + add_newline = False + else: + add_newline = True tmp.close() return temp_path