fix(ssh): Modify the return type of execWithPwd to include the output content

Adjust the return type of the `execWithPwd` method to `(int?, String)` so that it can simultaneously return the exit code and output content

Fix the issue in ContainerNotifier where the return result of execWithPwd is not handled correctly

Ensure that server operations (shutdown/restart/suspend) are correctly pending until the command execution is completed
This commit is contained in:
GT610
2026-01-11 22:03:02 +08:00
parent 06070c29b9
commit 0659e7f9d0
3 changed files with 26 additions and 23 deletions

View File

@@ -84,15 +84,14 @@ class ContainerNotifier extends _$ContainerNotifier {
}
final includeStats = Stores.setting.containerParseStat.fetch();
var raw = '';
final cmd = _wrap(ContainerCmdType.execAll(state.type, sudo: sudo, includeStats: includeStats));
final code = await client?.execWithPwd(
cmd,
context: context,
onStdout: (data, _) => raw = '$raw$data',
id: hostId,
);
int? code;
String raw = '';
if (client != null) {
(code, raw) = await client!.execWithPwd(cmd, context: context, id: hostId);
}
if (!ref.mounted) return;
state = state.copyWith(isBusy: false);
if (!context.mounted) return;
@@ -234,7 +233,7 @@ class ContainerNotifier extends _$ContainerNotifier {
state = state.copyWith(runLog: '');
final errs = <String>[];
final code = await client?.execWithPwd(
final (code, _) = await client?.execWithPwd(
_wrap((await sudoCompleter.future) ? 'sudo -S $cmd' : cmd),
context: context,
onStdout: (data, _) {
@@ -242,7 +241,7 @@ class ContainerNotifier extends _$ContainerNotifier {
},
onStderr: (data, _) => errs.add(data),
id: hostId,
);
) ?? (null, null);
state = state.copyWith(runLog: null);
if (code != 0) {