Skip to content

Commit 7d793f0

Browse files
committed
some cod cleanup
1 parent 5dec1f9 commit 7d793f0

2 files changed

Lines changed: 15 additions & 37 deletions

File tree

Sources/quickpkg/DMGManager.swift

Lines changed: 14 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ actor DMGManager {
5858
throw QuickPkgError.dmgMountFailed(result.standardError ?? "hdiutil info failed")
5959
}
6060

61-
let plistData = try PlistHandler.extractFirstPlist(from: Data((result.standardOutput ?? "").utf8))
61+
let plistData = try PlistHandler.extractFirstPlist(from: result.standardOutput ?? "")
6262
let info = try PlistHandler.parse(plistData)
63-
63+
6464
guard let images = info["images"] as? [[String: Any]] else {
6565
return nil
6666
}
@@ -118,42 +118,24 @@ actor DMGManager {
118118
"-plist",
119119
"-nobrowse"
120120
]
121+
let input: InputProtocol = sla ? .string("Y\n") : .none
121122

122123
logger.log("Executing: \(command) \(arguments)", level: 3)
123124

124-
let terminationStatus: TerminationStatus
125-
let standardOutput: String?
126-
let standardError: String?
127-
128-
if sla {
129-
let result = try await Subprocess.run(
130-
.path(command),
131-
arguments: arguments,
132-
input: .string("Y\n"),
133-
output: .string(limit: .max),
134-
error: .string(limit: .max)
135-
)
136-
terminationStatus = result.terminationStatus
137-
standardOutput = result.standardOutput
138-
standardError = result.standardError
139-
} else {
140-
let result = try await Subprocess.run(
141-
.path(command),
142-
arguments: arguments,
143-
output: .string(limit: .max),
144-
error: .string(limit: .max)
145-
)
146-
terminationStatus = result.terminationStatus
147-
standardOutput = result.standardOutput
148-
standardError = result.standardError
149-
}
150-
151-
guard terminationStatus.isSuccess else {
152-
throw QuickPkgError.dmgMountFailed(standardError ?? "hdiutil attach failed")
125+
let result = try await Subprocess.run(
126+
.path(command),
127+
arguments: arguments,
128+
input: input,
129+
output: .string(limit: .max),
130+
error: .string(limit: .max)
131+
)
132+
133+
guard result.terminationStatus.isSuccess else {
134+
throw QuickPkgError.dmgMountFailed(result.standardError ?? "hdiutil attach failed")
153135
}
154136

155137
// Parse the plist output to get mount points
156-
let plistData = try PlistHandler.extractFirstPlist(from: Data((standardOutput ?? "").utf8))
138+
let plistData = try PlistHandler.extractFirstPlist(from: result.standardOutput ?? "")
157139
let attachResult = try PlistHandler.parse(plistData)
158140

159141
var mountPoints: [URL] = []

Sources/quickpkg/PlistHandler.swift

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,7 @@ import Foundation
22

33
struct PlistHandler: Sendable {
44
/// Extract the first plist from mixed output (like hdiutil which returns text + plist)
5-
static func extractFirstPlist(from data: Data) throws -> Data {
6-
guard let string = String(data: data, encoding: .utf8) else {
7-
throw QuickPkgError.plistParsingFailed("Invalid UTF-8 data")
8-
}
9-
5+
static func extractFirstPlist(from string: String) throws -> Data {
106
let header = "<?xml version"
117
let footer = "</plist>"
128

0 commit comments

Comments
 (0)