From bc776a2e1364b5004d8e2601b2bafb8f93c6a396 Mon Sep 17 00:00:00 2001 From: Natalie Weizenbaum <nweiz@google.com> Date: Mon, 20 Jul 2015 14:48:19 -0700 Subject: [PATCH] Write binstubs using the system encoding. Closes #1304 R=rnystrom@google.com Review URL: https://codereview.chromium.org//1248483003 . --- lib/src/global_packages.dart | 5 ++++- lib/src/io.dart | 6 ++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/src/global_packages.dart b/lib/src/global_packages.dart index be7bad93..60eef15a 100644 --- a/lib/src/global_packages.dart +++ b/lib/src/global_packages.dart @@ -5,6 +5,7 @@ library pub.global_packages; import 'dart:async'; +import 'dart:convert'; import 'dart:io'; import 'package:path/path.dart' as p; @@ -694,7 +695,9 @@ pub global run ${package.name}:$script "\$@" """; } - writeTextFile(binStubPath, bash); + // Write this as the system encoding since the system is going to execute + // it and it might contain non-ASCII caharacters in the pathnames. + writeTextFile(binStubPath, bash, encoding: const SystemEncoding()); // Make it executable. var result = Process.runSync('chmod', ['+x', binStubPath]); diff --git a/lib/src/io.dart b/lib/src/io.dart index 2ec22ffc..8b7fc17c 100644 --- a/lib/src/io.dart +++ b/lib/src/io.dart @@ -165,14 +165,16 @@ List<int> readBinaryFile(String file) { /// /// If [dontLogContents] is true, the contents of the file will never be logged. String writeTextFile(String file, String contents, - {bool dontLogContents: false}) { + {bool dontLogContents: false, Encoding encoding}) { + if (encoding == null) encoding = UTF8; + // Sanity check: don't spew a huge file. log.io("Writing ${contents.length} characters to text file $file."); if (!dontLogContents && contents.length < 1024 * 1024) { log.fine("Contents:\n$contents"); } - new File(file).writeAsStringSync(contents); + new File(file).writeAsStringSync(contents, encoding: encoding); return file; } -- GitLab