diff --git a/pkg/private/deb/make_deb.py b/pkg/private/deb/make_deb.py index ee9bdc38..967b75b5 100644 --- a/pkg/private/deb/make_deb.py +++ b/pkg/private/deb/make_deb.py @@ -180,7 +180,10 @@ def CreateDebControl(extrafiles=None, **kwargs): if extrafiles: for name, (data, mode) in extrafiles.items(): tarinfo = tarfile.TarInfo('./' + name) - data_encoded = data.encode('utf-8') + if type(data) == type(b''): + data_encoded = data + else: + data_encoded = data.encode('utf-8') tarinfo.size = len(data_encoded) tarinfo.mode = mode f.addfile(tarinfo, fileobj=io.BytesIO(data_encoded)) diff --git a/pkg/private/helpers.py b/pkg/private/helpers.py index 5147cc2f..c503eb30 100644 --- a/pkg/private/helpers.py +++ b/pkg/private/helpers.py @@ -48,7 +48,7 @@ def SplitNameValuePairAtSeparator(arg, sep): # if we leave the loop, the character sep was not found unquoted return (head, '') -def GetFlagValue(flagvalue, strip=True): +def GetFlagValue(flagvalue, strip=True, encoding='utf-8'): """Converts a raw flag string to a useable value. 1. Expand @filename style flags to the content of filename. @@ -68,22 +68,36 @@ def GetFlagValue(flagvalue, strip=True): Python2: unicode Python3: str """ - if flagvalue: - if sys.version_info[0] < 3: - # python2 gives us raw bytes in argv. - flagvalue = flagvalue.decode('utf-8') - # assertion: py2: flagvalue is unicode - # assertion: py3: flagvalue is str, but in weird format - if flagvalue[0] == '@': - # Subtle: We do not want to re-encode the value here, because it - # is encoded in the right format for file open operations. - with open(flagvalue[1:], 'rb') as f: - flagvalue = f.read().decode('utf-8') + + if flagvalue is None: + return None + + if flagvalue and (sys.version_info[0] < 3): + # python2 gives us raw bytes in argv. + flagvalue = flagvalue.decode('utf-8') + + # assertion: py2: flagvalue is unicode + # assertion: py3: flagvalue is str, but in weird format + + if not flagvalue: + data = b'' + elif flagvalue[0] == '@': + with open(flagvalue[1:], 'rb') as f: + data = f.read() + else: + # Convert fs specific encoding back to proper unicode. + if sys.version_info[0] > 2: + data = os.fsencode(flagvalue) else: - # convert fs specific encoding back to proper unicode. - if sys.version_info[0] > 2: - flagvalue = os.fsencode(flagvalue).decode('utf-8') + data = flagvalue.encode('utf-8') + + # assertion: data is byte array. + + if not encoding: + return data + + value = data.decode(encoding) - if strip: - return flagvalue.strip() - return flagvalue + if strip: + return value.strip() + return value