From d31b8be0806815b1c01f36ec4b83126b1483c8b6 Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Fri, 21 Jun 2013 16:07:31 -0700 Subject: [PATCH] install.py: use surrogateescape for Python >=3.2 We can't trust that the filesystem encoding (locale dependent) correctly matches the arguments, so use surrogateescape to pass through the original argv bytes for Python 3. Since Python <3.2 does not support bytes in Popen args, trust the locale in that case. --- bin/install.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/bin/install.py b/bin/install.py index 2ca62f233..f7118a683 100755 --- a/bin/install.py +++ b/bin/install.py @@ -223,6 +223,20 @@ def main(args): path_installs = Which('install', all=True) cmdline = path_installs[0:1] cmdline += args + + if sys.hexversion >= 0x3020000: + # We can't trust that the filesystem encoding (locale dependent) + # correctly matches the arguments, so use surrogateescape to + # pass through the original argv bytes for Python 3. + # Since Python <3.2 does not support bytes in Popen args, trust + # the locale in that case. + fs_encoding = sys.getfilesystemencoding() + cmdline = [x.encode(fs_encoding, 'surrogateescape') for x in cmdline] + files = [x.encode(fs_encoding, 'surrogateescape') for x in files] + if opts.target_directory is not None: + opts.target_directory = \ + opts.target_directory.encode(fs_encoding, 'surrogateescape') + returncode = subprocess.call(cmdline) if returncode == os.EX_OK: returncode = copy_xattrs(opts, files) -- 2.26.2