From a07b5ee16c1368a5873cfa08e5f407cbe7d275f5 Mon Sep 17 00:00:00 2001 From: fengbaolong Date: Tue, 28 Apr 2020 16:37:02 +0800 Subject: fix docker build error when dockerfile contains unicode character. if dockerfile contains unicode character,len(contents) will return character length,this length will less than len(contents_encoded) length,so contants data will be truncated. Signed-off-by: fengbaolong --- docker/utils/build.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/docker/utils/build.py b/docker/utils/build.py index 4fa5751..5787cab 100644 --- a/docker/utils/build.py +++ b/docker/utils/build.py @@ -105,8 +105,9 @@ def create_archive(root, files=None, fileobj=None, gzip=False, for name, contents in extra_files: info = tarfile.TarInfo(name) - info.size = len(contents) - t.addfile(info, io.BytesIO(contents.encode('utf-8'))) + contents_encoded = contents.encode('utf-8') + info.size = len(contents_encoded) + t.addfile(info, io.BytesIO(contents_encoded)) t.close() fileobj.seek(0) -- cgit v1.2.1