Index: sdk/lib/_internal/pub/lib/src/io.dart |
diff --git a/sdk/lib/_internal/pub/lib/src/io.dart b/sdk/lib/_internal/pub/lib/src/io.dart |
index bd0dd7a257c28bd6b80a987a20cf3ed6f6c9bd68..5be7cb1c563c43cb09efe337a734251dfb945c35 100644 |
--- a/sdk/lib/_internal/pub/lib/src/io.dart |
+++ b/sdk/lib/_internal/pub/lib/src/io.dart |
@@ -794,7 +794,7 @@ Future<bool> extractTarGz(Stream<List<int>> stream, String destination) { |
} |
var args = ["--extract", "--gunzip", "--directory", destination]; |
- if (Platform.operatingSystem == "linux") { |
+ if (_noUnknownKeyword) { |
// BSD tar (the default on OS X) can insert strange headers to a tarfile |
// that GNU tar (the default on Linux) is unable to understand. This will |
// cause GNU tar to emit a number of harmless but scary-looking warnings |
@@ -822,6 +822,28 @@ Future<bool> extractTarGz(Stream<List<int>> stream, String destination) { |
}); |
} |
+/// Whether to include "--warning=no-unknown-keyword" when invoking tar. |
+/// |
+/// This flag quiets warnings that come from opening OS X-generated tarballs on |
+/// Linux, but only GNU tar >= 1.26 supports it. |
+final bool _noUnknownKeyword = _computeNoUnknownKeyword(); |
+bool _computeNoUnknownKeyword() { |
+ if (!Platform.isLinux) return false; |
+ var result = Process.runSync("tar", ["--version"]); |
+ if (result.exitCode != 0) { |
+ throw new ApplicationException( |
+ "Failed to run tar (exit code ${result.exitCode}):\n${result.stderr}"); |
+ } |
+ |
+ var match = new RegExp(r"^tar \(GNU tar\) (\d+).(\d+)\n") |
+ .firstMatch(result.stdout); |
+ if (match == null) return false; |
+ |
+ var major = int.parse(match[1]); |
+ var minor = int.parse(match[2]); |
+ return major >= 2 || (major == 1 && minor >= 23); |
+} |
+ |
String get pathTo7zip { |
if (runningFromSdk) return assetPath(path.join('7zip', '7za.exe')); |
return path.join(repoRoot, 'third_party', '7zip', '7za.exe'); |