Something went wrong. Try again.
An auto tiler for macOS
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950import Darwinimport Foundation
struct ReleaseConfirmation { static func run(_ args: [String]) throws { guard args.count == 2 else { throw DevError("Usage: release-confirmation SCRIPT OUTPUT_LOG") } let process = Process() let input = Pipe() let output = Pipe() process.executableURL = URL(fileURLWithPath: "/usr/bin/script") process.arguments = ["-q", "/dev/null", args[0]] process.standardInput = input process.standardOutput = output process.standardError = output try process.run() let deadline = ContinuousClock.now.advanced(by: .seconds(10)) var transcript = Data() var answered = false var finished = false do { while ContinuousClock.now < deadline { var descriptor = pollfd( fd: output.fileHandleForReading.fileDescriptor, events: Int16(POLLIN | POLLHUP), revents: 0) let status = poll(&descriptor, 1, 100) if status < 0 && errno == EINTR { continue } guard status >= 0 else { throw DevError("Could not read certificate confirmation") } if status == 0 { continue } var buffer = [UInt8](repeating: 0, count: 4096) let count = read(descriptor.fd, &buffer, buffer.count) guard count >= 0 else { throw DevError("Could not read certificate confirmation") } if count == 0 { finished = true; break } transcript.append(contentsOf: buffer.prefix(count)) if transcript.range(of: Data("[y/N]".utf8)) != nil && !answered { try input.fileHandleForWriting.write(contentsOf: Data("n\n".utf8)) answered = true } } guard finished else { throw DevError("Certificate confirmation did not finish") } process.waitUntilExit() try input.fileHandleForWriting.close() try transcript.write(to: URL(fileURLWithPath: args[1])) guard answered else { throw DevError("Certificate confirmation prompt was not shown") } } catch { if process.isRunning { kill(process.processIdentifier, SIGKILL); process.waitUntilExit() } try transcript.write(to: URL(fileURLWithPath: args[1])) throw error } }}