Skip to content

Commit 3fe8e19

Browse files
committed
swiftlint cleanup
1 parent d7f2566 commit 3fe8e19

10 files changed

Lines changed: 61 additions & 61 deletions

Sources/quickpkg/ArchiveExtractor.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,33 @@ import Foundation
33
struct ArchiveExtractor: Sendable {
44
let executor: ShellExecutor
55
let logger: Logger
6-
6+
77
/// Extract a zip archive to the specified directory
88
func extractZip(_ archivePath: URL, to destinationDir: URL) async throws {
99
logger.log("Extracting zip: \(archivePath.path) to \(destinationDir.path)", level: 1)
10-
10+
1111
let result = try await executor.run([
1212
"/usr/bin/unzip",
1313
"-q",
1414
archivePath.path,
1515
"-d", destinationDir.path
1616
])
17-
17+
1818
guard result.exitCode == 0 else {
1919
throw QuickPkgError.archiveExtractionFailed("unzip failed (\(result.exitCode)): \(result.stderr)")
2020
}
2121
}
22-
22+
2323
/// Extract a xip archive to the specified directory
2424
func extractXip(_ archivePath: URL, to destinationDir: URL) async throws {
2525
logger.log("Extracting xip: \(archivePath.path) to \(destinationDir.path)", level: 1)
26-
26+
2727
// xip --expand extracts to the current directory, so we need to run it from the destination
2828
let result = try await executor.run(
2929
["/usr/bin/xip", "--expand", archivePath.path],
3030
workingDirectory: destinationDir
3131
)
32-
32+
3333
guard result.exitCode == 0 else {
3434
throw QuickPkgError.archiveExtractionFailed("xip failed (\(result.exitCode)): \(result.stderr)")
3535
}

Sources/quickpkg/DMGManager.swift

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,48 +5,48 @@ actor DMGManager {
55
private let logger: Logger
66
private var wasMounted: [URL: Bool] = [:]
77
private var mountedVolumes: [URL] = []
8-
8+
99
init(
1010
executor: ShellExecutor,
1111
logger: Logger
1212
) {
1313
self.executor = executor
1414
self.logger = logger
1515
}
16-
16+
1717
/// Check if a DMG has a Software License Agreement
1818
func hasSLA(at path: URL) async throws -> Bool {
1919
let result = try await executor.runOrThrow([
2020
"/usr/bin/hdiutil", "imageinfo", path.path, "-plist"
2121
])
22-
22+
2323
let plist = try PlistHandler.parse(Data(result.stdout.utf8))
2424
if let properties = plist["Properties"] as? [String: Any],
2525
let hasSLA = properties["Software License Agreement"] as? Bool {
2626
return hasSLA
2727
}
2828
return false
2929
}
30-
30+
3131
/// Check if DMG is already mounted and return mount points
3232
func existingMountPoints(for dmgPath: URL) async throws -> [URL]? {
3333
let result = try await executor.runOrThrow(["/usr/bin/hdiutil", "info", "-plist"])
34-
34+
3535
let plistData = try PlistHandler.extractFirstPlist(from: Data(result.stdout.utf8))
3636
let info = try PlistHandler.parse(plistData)
37-
37+
3838
guard let images = info["images"] as? [[String: Any]] else {
3939
return nil
4040
}
41-
41+
4242
for image in images {
4343
guard let imagePath = image["image-path"] as? String else { continue }
44-
44+
4545
// Check if this is our DMG (compare paths)
4646
let imageURL = URL(filePath: imagePath)
4747
if imageURL.standardizedFileURL == dmgPath.standardizedFileURL ||
4848
FileManager.default.contentsEqual(atPath: imageURL.path, andPath: dmgPath.path) {
49-
49+
5050
var mountPoints: [URL] = []
5151
if let entities = image["system-entities"] as? [[String: Any]] {
5252
for entity in entities {
@@ -55,7 +55,7 @@ actor DMGManager {
5555
}
5656
}
5757
}
58-
58+
5959
if !mountPoints.isEmpty {
6060
// Mark as pre-mounted so we don't detach it
6161
for mp in mountPoints {
@@ -65,24 +65,24 @@ actor DMGManager {
6565
}
6666
}
6767
}
68-
68+
6969
return nil
7070
}
71-
71+
7272
/// Attach a DMG and return mount points
7373
func attach(_ dmgPath: URL) async throws -> [URL] {
7474
// First check if already mounted
7575
if let existing = try await existingMountPoints(for: dmgPath) {
7676
logger.log("DMG already mounted at: \(existing.map(\.path).joined(separator: ", "))", level: 1)
7777
return existing
7878
}
79-
79+
8080
// Check for SLA
8181
let sla = try await hasSLA(at: dmgPath)
8282
if sla {
8383
logger.log("NOTE: Disk image \(dmgPath.path) has a license agreement!", level: 0)
8484
}
85-
85+
8686
// Mount the DMG
8787
let arguments = [
8888
"/usr/bin/hdiutil",
@@ -92,17 +92,17 @@ actor DMGManager {
9292
"-plist",
9393
"-nobrowse"
9494
]
95-
95+
9696
let result = try await executor.run(arguments, input: sla ? "Y\n" : nil)
97-
97+
9898
guard result.exitCode == 0 else {
9999
throw QuickPkgError.dmgMountFailed("(\(result.exitCode)) \(result.stderr)")
100100
}
101-
101+
102102
// Parse the plist output to get mount points
103103
let plistData = try PlistHandler.extractFirstPlist(from: Data(result.stdout.utf8))
104104
let attachResult = try PlistHandler.parse(plistData)
105-
105+
106106
var mountPoints: [URL] = []
107107
if let entities = attachResult["system-entities"] as? [[String: Any]] {
108108
for entity in entities {
@@ -118,33 +118,33 @@ actor DMGManager {
118118
}
119119
}
120120
}
121-
121+
122122
logger.log("Mounted DMG at: \(mountPoints.map(\.path).joined(separator: ", "))", level: 1)
123123
return mountPoints
124124
}
125-
125+
126126
/// Detach a mounted volume
127127
func detach(_ mountPoint: URL) async throws {
128128
// Don't detach if it was already mounted before we started
129129
if wasMounted[mountPoint] == true {
130130
logger.log("Skipping detach for pre-mounted volume: \(mountPoint.path)", level: 2)
131131
return
132132
}
133-
133+
134134
guard FileManager.default.fileExists(atPath: mountPoint.path) else { return }
135-
135+
136136
let result = try await executor.run(["/usr/bin/hdiutil", "detach", mountPoint.path])
137-
137+
138138
if result.exitCode != 0 {
139139
logger.log("Warning: Failed to detach \(mountPoint.path): \(result.stderr)", level: 1)
140140
} else {
141141
logger.log("Detached: \(mountPoint.path)", level: 2)
142142
}
143-
143+
144144
mountedVolumes.removeAll { $0 == mountPoint }
145145
wasMounted.removeValue(forKey: mountPoint)
146146
}
147-
147+
148148
/// Detach all volumes that we mounted
149149
func detachAll() async {
150150
for volume in mountedVolumes {

Sources/quickpkg/InputType.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ enum InputType: String, CaseIterable {
66
case dmg
77
case zip
88
case xip
9-
9+
1010
static func from(path: String) -> InputType? {
1111
let ext = URL(filePath: path).pathExtension.lowercased()
1212
return InputType(rawValue: ext)

Sources/quickpkg/Logger.swift

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

33
struct Logger: Sendable {
44
let verbosity: Int
5-
5+
66
func log(_ message: String, level: Int = 0) {
77
if verbosity >= level {
88
print(message)

Sources/quickpkg/PackageBuilder.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import Foundation
33
struct PackageBuilder: Sendable {
44
let executor: ShellExecutor
55
let logger: Logger
6-
6+
77
/// Analyze the payload and create a component plist
88
func analyze(
99
payloadDir: URL,
@@ -21,11 +21,11 @@ struct PackageBuilder: Sendable {
2121
"--install-location", installLocation,
2222
outputPlist.path
2323
]
24-
24+
2525
let result = try await executor.runOrThrow(arguments)
2626
logger.log(result.stdout, level: 1)
2727
}
28-
28+
2929
/// Build the package
3030
func build(
3131
payloadDir: URL,

Sources/quickpkg/PlistHandler.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,46 +6,46 @@ struct PlistHandler: Sendable {
66
guard let string = String(data: data, encoding: .utf8) else {
77
throw QuickPkgError.plistParsingFailed("Invalid UTF-8 data")
88
}
9-
9+
1010
let header = "<?xml version"
1111
let footer = "</plist>"
12-
12+
1313
guard let startRange = string.range(of: header),
1414
let endRange = string.range(of: footer, range: startRange.upperBound..<string.endIndex) else {
1515
throw QuickPkgError.plistParsingFailed("No plist found in output")
1616
}
17-
17+
1818
let plistString = String(string[startRange.lowerBound..<endRange.upperBound]) + "\n"
1919
return Data(plistString.utf8)
2020
}
21-
21+
2222
/// Parse plist data into a dictionary
2323
static func parse(_ data: Data) throws -> [String: Any] {
2424
guard let plist = try PropertyListSerialization.propertyList(from: data, format: nil) as? [String: Any] else {
2525
throw QuickPkgError.plistParsingFailed("Invalid plist format - expected dictionary")
2626
}
2727
return plist
2828
}
29-
29+
3030
/// Parse plist data into an array of dictionaries
3131
static func parseArray(_ data: Data) throws -> [[String: Any]] {
3232
guard let plist = try PropertyListSerialization.propertyList(from: data, format: nil) as? [[String: Any]] else {
3333
throw QuickPkgError.plistParsingFailed("Invalid plist format - expected array")
3434
}
3535
return plist
3636
}
37-
37+
3838
/// Modify component plist to set BundleIsRelocatable
3939
static func setRelocatable(_ relocatable: Bool, in plistURL: URL) throws {
4040
let data = try Data(contentsOf: plistURL)
4141
var components = try parseArray(data)
42-
42+
4343
for i in components.indices {
4444
if components[i]["BundleIsRelocatable"] != nil {
4545
components[i]["BundleIsRelocatable"] = relocatable
4646
}
4747
}
48-
48+
4949
let outputData = try PropertyListSerialization.data(
5050
fromPropertyList: components,
5151
format: .xml,

Sources/quickpkg/QuickPkg.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ struct QuickPkg: AsyncParsableCommand {
1212
Quickly build a package from an installed application, a disk image file,
1313
or zip/xip archive with an enclosed application bundle.
1414
15-
The tool extracts the application name, version, and other metadata from the application
15+
The tool extracts the application name, version, and other metadata from the application
1616
for the package installer metadata and to name the resulting pkg file.
1717
1818
Example: quickpkg /path/to/installer_item

Sources/quickpkg/QuickPkgError.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ enum QuickPkgError: LocalizedError {
1515
case scriptConflict(String)
1616
case commandFailed(command: String, exitCode: Int32, stderr: String)
1717
case plistParsingFailed(String)
18-
18+
1919
var errorDescription: String? {
2020
switch self {
2121
case .unsupportedExtension(let ext):

Sources/quickpkg/ShellExecutor.swift

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,37 +9,37 @@ import SystemPackage
99

1010
struct ShellExecutor: Sendable {
1111
let logger: Logger
12-
12+
1313
struct CommandResult: Sendable {
1414
let stdout: String
1515
let stderr: String
1616
let exitCode: Int32
1717
}
18-
18+
1919
func run(
2020
_ arguments: [String],
2121
input inputString: String? = nil,
2222
workingDirectory: URL? = nil
2323
) async throws -> CommandResult {
2424
logger.log("Executing: \(arguments.joined(separator: " "))", level: 3)
25-
25+
2626
guard let executable = arguments.first else {
2727
throw QuickPkgError.commandFailed(command: "", exitCode: -1, stderr: "No command specified")
2828
}
29-
29+
3030
let args = Array(arguments.dropFirst())
3131
let maxOutputSize = 10 * 1024 * 1024 // 10 MB limit
3232
let workDir = workingDirectory.map { FilePath($0.path) }
33-
33+
3434
let result: CollectedResult<StringOutput<UTF8>, StringOutput<UTF8>>
35-
35+
3636
let input: InputProtocol
3737
if let inputString {
3838
input = .string(inputString)
3939
} else {
4040
input = .none
4141
}
42-
42+
4343
result = try await Subprocess.run(
4444
.path(FilePath(executable)),
4545
arguments: Arguments(args),
@@ -48,34 +48,34 @@ struct ShellExecutor: Sendable {
4848
output: .string(limit: maxOutputSize, encoding: UTF8.self),
4949
error: .string(limit: maxOutputSize, encoding: UTF8.self)
5050
)
51-
51+
5252
let stdout = (result.standardOutput ?? "")
5353
.trimmingCharacters(in: .whitespacesAndNewlines)
5454
let stderr = (result.standardError ?? "")
5555
.trimmingCharacters(in: .whitespacesAndNewlines)
56-
56+
5757
let exitCode: Int32
5858
switch result.terminationStatus {
5959
case .exited(let code):
6060
exitCode = code
6161
case .unhandledException(let code):
6262
exitCode = code
6363
}
64-
64+
6565
return CommandResult(stdout: stdout, stderr: stderr, exitCode: exitCode)
6666
}
67-
67+
6868
func runOrThrow(_ arguments: [String], input: String? = nil, workingDirectory: URL? = nil) async throws -> CommandResult {
6969
let result = try await run(arguments, input: input, workingDirectory: workingDirectory)
70-
70+
7171
logger.log("Exit code: \(result.exitCode)", level: 3)
7272
if !result.stdout.isEmpty {
7373
logger.log("stdout: \(result.stdout)", level: 3)
7474
}
7575
if !result.stderr.isEmpty {
7676
logger.log("stderr: \(result.stderr)", level: 3)
7777
}
78-
78+
7979
guard result.exitCode == 0 else {
8080
throw QuickPkgError.commandFailed(
8181
command: arguments.joined(separator: " "),

0 commit comments

Comments
 (0)