Skip to content

Commit

Permalink
Moved logic to get the Xcode's expansion directory to a function insi…
Browse files Browse the repository at this point in the history
…de `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`.
  • Loading branch information
juanjonol committed Feb 6, 2022
1 parent 239898f commit f1163aa
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
6 changes: 6 additions & 0 deletions Sources/XcodesKit/Environment.swift
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,12 @@ public struct Files {
return try temporalDirectory(URL)
}

public var xcodeExpansionDirectory: (URL, URL) -> URL = { (try? Current.files.temporalDirectory(for: $1)) ?? $0.deletingLastPathComponent() }

public func xcodeExpansionDirectory(archiveURL: URL, xcodeURL: URL) -> URL {
return xcodeExpansionDirectory(archiveURL, xcodeURL)
}

public var installedXcodes = XcodesKit.installedXcodes
}
private func installedXcodes(directory: Path) -> [InstalledXcode] {
Expand Down
2 changes: 1 addition & 1 deletion Sources/XcodesKit/XcodeInstaller.swift
Original file line number Diff line number Diff line change
Expand Up @@ -718,7 +718,7 @@ public final class XcodeInstaller {
}

func unarchiveAndMoveXIP(at source: URL, to destination: URL) -> Promise<URL> {
let xcodeExpansionDirectory = (try? Current.files.temporalDirectory(for: destination)) ?? source.deletingLastPathComponent()
let xcodeExpansionDirectory = Current.files.xcodeExpansionDirectory(archiveURL: source, xcodeURL: destination)
return firstly { () -> Promise<ProcessOutput> in
Current.logging.log(InstallationStep.unarchiving.description)
return Current.shell.unxip(source, xcodeExpansionDirectory)
Expand Down
1 change: 1 addition & 0 deletions Tests/XcodesKitTests/Environment+Mock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ extension Files {
createFile: { _, _, _ in return true },
createDirectory: { _, _, _ in },
temporalDirectory: { _ in return URL(fileURLWithPath: NSTemporaryDirectory()) },
xcodeExpansionDirectory: { _, _ in return URL(fileURLWithPath: NSTemporaryDirectory()) },
installedXcodes: { _ in [] }
)
}
Expand Down

0 comments on commit f1163aa

Please sign in to comment.