Visitar URL original
Use process.start instead of process.run in ssh client. by godofredoc · Pull Request #178 · flutter/packages · GitHub
Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add license to file.
  • Loading branch information
godofredoc committed Oct 15, 2020
commit d89bdd2af52d0e15c1a55c990231b1dcd295138e
28 changes: 11 additions & 17 deletions packages/fuchsia_ctl/lib/src/ssh_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ class SshClient {
final ProcessManager processManager;

/// The default ssh timeout as [Duration] in milliseconds.
static const Duration defaultSshTimeoutMs =
Duration(milliseconds: 5 * 60 * 1000);
static const Duration defaultSshTimeoutMs = Duration(milliseconds: 5 * 60 * 1000);

/// Creates a list of arguments to pass to ssh.
///
Expand Down Expand Up @@ -112,8 +111,7 @@ class SshClient {
// If no file is passed to this method we create a memoryfile to keep to
// return the stdout in OperationResult.
if (logToFile) {
fileSystem.file(logFilePath).existsSync() ??
fileSystem.file(logFilePath).deleteSync();
fileSystem.file(logFilePath).existsSync() ?? fileSystem.file(logFilePath).deleteSync();
fileSystem.file(logFilePath).createSync();
final IOSink data = fileSystem.file(logFilePath).openWrite();
logger = PrintLogger(out: data);
Expand All @@ -131,23 +129,21 @@ class SshClient {
command: command,
),
);
final StreamSubscription<String> stdoutSubscription = process.stdout
.transform(utf8.decoder)
.transform(const LineSplitter())
.listen((String log) {
final StreamSubscription<String> stdoutSubscription =
process.stdout.transform(utf8.decoder).transform(const LineSplitter()).listen((String log) {
if (!logToFile) {
logFile.writeln(log);
} else {
logger.info(log);
}
logger.info(log);
});
final StreamSubscription<String> stderrSubscription = process.stderr
.transform(utf8.decoder)
.transform(const LineSplitter())
.listen((String log) {
final StreamSubscription<String> stderrSubscription =
process.stderr.transform(utf8.decoder).transform(const LineSplitter()).listen((String log) {
if (!logToFile) {
logFile.writeln(log);
} else {
logger.warning(log);
}
logger.warning(log);
});

// Wait for stdout and stderr to be fully processed because proc.exitCode
Expand All @@ -171,8 +167,6 @@ class SshClient {
output = await fileSystem.file('logs').readAsString();
}

return exitCode != 0
? OperationResult.error('Failed', info: output)
: OperationResult.success(info: output);
return exitCode != 0 ? OperationResult.error('Failed', info: output) : OperationResult.success(info: output);
}
}