Skip to content

Commit f1163aa

Browse files
committed
Moved logic to get the Xcode's expansion directory to a function inside Files
As suggested by @MattKiazyk, to be able to get the expansion directory by simply calling `Current.files.xcodeExpansionDirectory()`. - The `Files.temporalDirectory()` added on the previous commits is keep even if it's not used outside `Files.xcodeExpansionDirectory()`, to keep each function with a single statement (as the other functions on `Files`). - I'm not sure there's value on adding the `xcodeExpansionDirectory` variable, but added for consistency with the other functions on `Files`.
1 parent 239898f commit f1163aa

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

Sources/XcodesKit/Environment.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,12 @@ public struct Files {
244244
return try temporalDirectory(URL)
245245
}
246246

247+
public var xcodeExpansionDirectory: (URL, URL) -> URL = { (try? Current.files.temporalDirectory(for: $1)) ?? $0.deletingLastPathComponent() }
248+
249+
public func xcodeExpansionDirectory(archiveURL: URL, xcodeURL: URL) -> URL {
250+
return xcodeExpansionDirectory(archiveURL, xcodeURL)
251+
}
252+
247253
public var installedXcodes = XcodesKit.installedXcodes
248254
}
249255
private func installedXcodes(directory: Path) -> [InstalledXcode] {

Sources/XcodesKit/XcodeInstaller.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -718,7 +718,7 @@ public final class XcodeInstaller {
718718
}
719719

720720
func unarchiveAndMoveXIP(at source: URL, to destination: URL) -> Promise<URL> {
721-
let xcodeExpansionDirectory = (try? Current.files.temporalDirectory(for: destination)) ?? source.deletingLastPathComponent()
721+
let xcodeExpansionDirectory = Current.files.xcodeExpansionDirectory(archiveURL: source, xcodeURL: destination)
722722
return firstly { () -> Promise<ProcessOutput> in
723723
Current.logging.log(InstallationStep.unarchiving.description)
724724
return Current.shell.unxip(source, xcodeExpansionDirectory)

Tests/XcodesKitTests/Environment+Mock.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ extension Files {
6161
createFile: { _, _, _ in return true },
6262
createDirectory: { _, _, _ in },
6363
temporalDirectory: { _ in return URL(fileURLWithPath: NSTemporaryDirectory()) },
64+
xcodeExpansionDirectory: { _, _ in return URL(fileURLWithPath: NSTemporaryDirectory()) },
6465
installedXcodes: { _ in [] }
6566
)
6667
}

0 commit comments

Comments
 (0)