From 20cd8cc2c999decfad79d96a2f2ef74fa0e490d0 Mon Sep 17 00:00:00 2001 From: Kare Morstol Date: Tue, 26 Mar 2019 17:41:56 +0100 Subject: [PATCH] Don't verify file is executable before running it. Also remove unneeded Equatable implementation. --- Sources/SwiftShell/Command.swift | 15 +-------------- Sources/SwiftShell/Process.swift | 5 +++-- 2 files changed, 4 insertions(+), 16 deletions(-) diff --git a/Sources/SwiftShell/Command.swift b/Sources/SwiftShell/Command.swift index e41b787..1baaf40 100755 --- a/Sources/SwiftShell/Command.swift +++ b/Sources/SwiftShell/Command.swift @@ -83,7 +83,7 @@ extension CommandRunning { // MARK: CommandError /** Error type for commands. */ -public enum CommandError: Error { +public enum CommandError: Error, Equatable { /** Exit code was not zero. */ case returnedErrorCode(command: String, errorcode: Int) @@ -113,19 +113,6 @@ extension CommandError: CustomStringConvertible { } } -extension CommandError: Equatable { - static public func == (e1: CommandError, e2: CommandError) -> Bool { - switch (e1, e2) { - case (.returnedErrorCode(let c1), .returnedErrorCode(let c2)): - return c1.errorcode == c2.errorcode && c1.command == c2.command - case (.inAccessibleExecutable(let c1), .inAccessibleExecutable(let c2)): - return c1 == c2 - case (.inAccessibleExecutable, .returnedErrorCode), (.returnedErrorCode, .inAccessibleExecutable): - return false - } - } -} - // MARK: run /// Output from a `run` command. diff --git a/Sources/SwiftShell/Process.swift b/Sources/SwiftShell/Process.swift index ba76641..dd7a007 100644 --- a/Sources/SwiftShell/Process.swift +++ b/Sources/SwiftShell/Process.swift @@ -16,10 +16,11 @@ extension Process { /// /// - throws: CommandError.inAccessibleExecutable if command could not be executed. public func launchThrowably() throws { - guard Files.isExecutableFile(atPath: self.executableURL!.path) else { + do { + try run() + } catch CocoaError.fileNoSuchFile { throw CommandError.inAccessibleExecutable(path: self.executableURL!.lastPathComponent) } - try run() } /// Waits until process is finished.