From 7a6d9970e886a094908c01983e07aa6126bd2f87 Mon Sep 17 00:00:00 2001 From: Riley Testut Date: Fri, 14 Feb 2020 17:02:15 -0800 Subject: [PATCH] [AltServer] Fixes plug-in installation error when plug-ins directory does not exist --- AltServer/AppDelegate.swift | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/AltServer/AppDelegate.swift b/AltServer/AppDelegate.swift index c4dcca65..34a3790f 100644 --- a/AltServer/AppDelegate.swift +++ b/AltServer/AppDelegate.swift @@ -338,8 +338,11 @@ private extension AppDelegate let fileURL = try result.get() defer { try? FileManager.default.removeItem(at: fileURL) } + // Ensure plug-in directory exists. + let authorization = try self.runAndKeepAuthorization("mkdir", arguments: ["-p", pluginDirectoryURL.path]) + // Unzip AltPlugin to plug-ins directory. - let authorization = try self.runAndKeepAuthorization("unzip", arguments: ["-o", fileURL.path, "-d", pluginDirectoryURL.path]) + try self.runAndKeepAuthorization("unzip", arguments: ["-o", fileURL.path, "-d", pluginDirectoryURL.path], authorization: authorization) guard self.isMailPluginInstalled else { throw PluginError.unknown } // Enable Mail plug-in preferences. @@ -420,6 +423,7 @@ private extension AppDelegate _ = try self._run(program, arguments: arguments, authorization: authorization, freeAuthorization: true) } + @discardableResult func runAndKeepAuthorization(_ program: String, arguments: [String], authorization: AuthorizationRef? = nil) throws -> AuthorizationRef { return try self._run(program, arguments: arguments, authorization: authorization, freeAuthorization: false) @@ -455,6 +459,8 @@ private extension AppDelegate task.waitUntilExit() + print("Exit code:", task.terminationStatus) + guard task.terminationStatus == 0 else { let outputData = task.outputFileHandle.readDataToEndOfFile()