fix: bad check of script writing result (#275)

This commit is contained in:
lollipopkit
2024-02-18 17:34:42 +08:00
parent b802c97a8d
commit ab058cc094
5 changed files with 41 additions and 39 deletions

View File

@@ -259,25 +259,30 @@ class ServerProvider extends ChangeNotifier {
}
Future<void> _writeInstallerScript(Server s) async {
void ensure(String? writeResult) {
if (writeResult == null || writeResult.isNotEmpty) {
throw Exception("Failed to write installer script: $writeResult");
}
}
/// TODO: Find a better way to judge if the write is successful
// Issues #275
// Can't use writeResult to judge if the write is successful
// void ensure(String? writeResult) {
// if (writeResult == null || writeResult.isNotEmpty) {
// throw Exception("Failed to write installer script: $writeResult");
// }
// }
final client = s.client;
if (client == null) {
throw Exception("Invalid state: s.client cannot be null");
}
ensure(await client.run(ShellFunc.installerMkdirs).string);
await client.run(ShellFunc.installerMkdirs).string;
ensure(await client.runForOutput(ShellFunc.installerShellWriter,
await client.runForOutput(ShellFunc.installerShellWriter,
action: (session) async {
session.stdin.add(ShellFunc.allScript.uint8List);
}).string);
}).string;
ensure(await client.run(ShellFunc.installerPermissionModifier).string);
await client.run(ShellFunc.installerPermissionModifier).string;
}
Future<void> _getData(ServerPrivateInfo spi) async {