mirror of
https://github.com/nimbold/Firelink.git
synced 2026-08-08 10:23:29 +00:00
fix: resolve additional bugs identified in code review
- core: remove DispatchGroup from MediaExtractionEngine to fix hanging on yt-dlp launch failure - core: clear readabilityHandlers in Aria2DownloadEngine if process fails to launch - core: fix TOCTOU type warning for findFreePort - build: fix inverted logic in Mach-O validation script - ci: fix hardcoded macOS SDK version check in release workflow - ci: prevent workflow_dispatch from failing on verify-tag
This commit is contained in:
@@ -10,7 +10,7 @@ final class Aria2DownloadEngine: Sendable {
|
||||
let cancel: @Sendable () -> Void
|
||||
}
|
||||
|
||||
static func findFreePort() -> Int {
|
||||
static func findFreePort() -> UInt16 {
|
||||
var port: UInt16 = 6800
|
||||
let parameters = NWParameters.tcp
|
||||
for p in 6800...6900 {
|
||||
@@ -21,7 +21,7 @@ final class Aria2DownloadEngine: Sendable {
|
||||
break
|
||||
}
|
||||
}
|
||||
return Int(port)
|
||||
return port
|
||||
}
|
||||
|
||||
enum EngineError: LocalizedError {
|
||||
@@ -120,7 +120,7 @@ final class Aria2DownloadEngine: Sendable {
|
||||
var lastError: Error?
|
||||
|
||||
for _ in 1...5 {
|
||||
let rpcPort = Self.findFreePort()
|
||||
let rpcPort = Int(Self.findFreePort())
|
||||
let rpcSecret = UUID().uuidString
|
||||
let tempDir = URL(fileURLWithPath: NSTemporaryDirectory()).appendingPathComponent("firelink-aria2-\(UUID().uuidString)")
|
||||
|
||||
@@ -221,6 +221,8 @@ final class Aria2DownloadEngine: Sendable {
|
||||
}
|
||||
|
||||
if didThrow {
|
||||
outputPipe.fileHandleForReading.readabilityHandler = nil
|
||||
errorPipe.fileHandleForReading.readabilityHandler = nil
|
||||
try? FileManager.default.removeItem(at: tempDir)
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -416,16 +416,10 @@ private final class YTDLPMetadataProcess: @unchecked Sendable {
|
||||
process.standardError = errorPipe
|
||||
process.standardInput = nil
|
||||
|
||||
let group = DispatchGroup()
|
||||
group.enter() // output
|
||||
group.enter() // error
|
||||
group.enter() // process
|
||||
|
||||
outputPipe.fileHandleForReading.readabilityHandler = { handle in
|
||||
let data = handle.availableData
|
||||
if data.isEmpty {
|
||||
handle.readabilityHandler = nil
|
||||
group.leave()
|
||||
} else {
|
||||
outputBuffer.append(data)
|
||||
}
|
||||
@@ -435,7 +429,6 @@ private final class YTDLPMetadataProcess: @unchecked Sendable {
|
||||
let data = handle.availableData
|
||||
if data.isEmpty {
|
||||
handle.readabilityHandler = nil
|
||||
group.leave()
|
||||
} else {
|
||||
errorBuffer.append(data)
|
||||
}
|
||||
@@ -445,12 +438,11 @@ private final class YTDLPMetadataProcess: @unchecked Sendable {
|
||||
self.process = process
|
||||
}
|
||||
|
||||
process.terminationHandler = { _ in
|
||||
group.leave()
|
||||
}
|
||||
|
||||
group.notify(queue: .global()) {
|
||||
if process.terminationStatus == 0 {
|
||||
process.terminationHandler = { finishedProcess in
|
||||
outputPipe.fileHandleForReading.readabilityHandler = nil
|
||||
errorPipe.fileHandleForReading.readabilityHandler = nil
|
||||
|
||||
if finishedProcess.terminationStatus == 0 {
|
||||
continuation.resume(returning: outputBuffer.data)
|
||||
} else {
|
||||
let stderr = String(data: errorBuffer.data, encoding: .utf8)?
|
||||
@@ -463,7 +455,7 @@ private final class YTDLPMetadataProcess: @unchecked Sendable {
|
||||
.joined(separator: "\n")
|
||||
continuation.resume(
|
||||
throwing: MediaExtractionEngine.ExtractionError.processFailed(
|
||||
message.isEmpty ? "Exit code \(process.terminationStatus)" : message
|
||||
message.isEmpty ? "Exit code \(finishedProcess.terminationStatus)" : message
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user