Skip to content

Commit e0947fe

Browse files
committed
added fileExists URL extension
1 parent 3fe8e19 commit e0947fe

3 files changed

Lines changed: 15 additions & 6 deletions

File tree

Sources/quickpkg/DMGManager.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ actor DMGManager {
131131
return
132132
}
133133

134-
guard FileManager.default.fileExists(atPath: mountPoint.path) else { return }
134+
guard mountPoint.fileExists else { return }
135135

136136
let result = try await executor.run(["/usr/bin/hdiutil", "detach", mountPoint.path])
137137

Sources/quickpkg/QuickPkg.swift

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ struct QuickPkg: AsyncParsableCommand {
233233
dmgManager: DMGManager,
234234
archiveExtractor: ArchiveExtractor
235235
) async throws -> URL {
236-
guard FileManager.default.fileExists(atPath: url.path) else {
236+
guard url.fileExists else {
237237
throw QuickPkgError.fileNotFound(url.path)
238238
}
239239

@@ -265,7 +265,7 @@ struct QuickPkg: AsyncParsableCommand {
265265

266266
if let scriptsPath = scripts {
267267
let scriptsURL = URL(filePath: scriptsPath)
268-
guard FileManager.default.fileExists(atPath: scriptsPath) else {
268+
guard scriptsURL.fileExists else {
269269
throw QuickPkgError.scriptNotFound(scriptsPath)
270270
}
271271
scriptsDir = scriptsURL
@@ -301,11 +301,11 @@ struct QuickPkg: AsyncParsableCommand {
301301
/// Copy a script to the scripts directory with proper permissions
302302
private func copyScript(from sourcePath: String, to scriptsDir: URL, name: String, logger: Logger) throws {
303303
let sourceURL = URL(filePath: sourcePath)
304-
guard FileManager.default.fileExists(atPath: sourcePath) else {
304+
guard sourceURL.fileExists else {
305305
throw QuickPkgError.scriptNotFound(sourcePath)
306306
}
307307
let destURL = scriptsDir.appendingPathComponent(name)
308-
if FileManager.default.fileExists(atPath: destURL.path) {
308+
if destURL.fileExists {
309309
throw QuickPkgError.scriptConflict("\(name) script already exists in scripts folder")
310310
}
311311
try FileManager.default.copyItem(at: sourceURL, to: destURL)
@@ -319,7 +319,8 @@ struct QuickPkg: AsyncParsableCommand {
319319
var path: String
320320

321321
if let output = output {
322-
if FileManager.default.fileExists(atPath: output),
322+
let outputURL = URL(filePath: output)
323+
if outputURL.fileExists,
323324
(try? FileManager.default.attributesOfItem(atPath: output)[.type] as? FileAttributeType) == .typeDirectory {
324325
path = (output as NSString).appendingPathComponent(defaultName)
325326
} else {
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import Foundation
2+
3+
extension URL {
4+
/// Returns true if this is a file URL and the file exists
5+
var fileExists: Bool {
6+
isFileURL && FileManager.default.fileExists(atPath: path)
7+
}
8+
}

0 commit comments

Comments
 (0)