Skip to content

Commit

Permalink
Merge pull request Carthage#57 from ffittschen/bugfix/tar-binaries
Browse files Browse the repository at this point in the history
Add support for tar binaries in BinaryProjectCache
  • Loading branch information
werner77 committed May 23, 2020
2 parents ebef768 + f571973 commit 8c7e16a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
9 changes: 6 additions & 3 deletions Source/CarthageKit/Archive.swift
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,16 @@ public final class Archive {

// MARK: - Internal

static func hasTarExtension(fileURL: URL) -> Bool {
return ["gz", "tgz", "bz2", "xz"].contains(fileURL.pathExtension)
}

/// Unarchives the given file URL into a temporary directory, using its
/// extension to detect archive type, then sends the file URL to that directory.
static func unarchive(archive fileURL: URL) -> SignalProducer<URL, CarthageError> {
switch fileURL.pathExtension {
case "gz", "tgz", "bz2", "xz":
if hasTarExtension(fileURL: fileURL) {
return untar(archive: fileURL)
default:
} else {
return unzip(archive: fileURL)
}
}
Expand Down
21 changes: 20 additions & 1 deletion Source/CarthageKit/BinariesCache.swift
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,30 @@ final class BinaryProjectCache: AbstractBinariesCache {
if let httpResponse = response as? HTTPURLResponse, !(200...299).contains(httpResponse.statusCode) {
return SignalProducer(error: CarthageError.httpError(statusCode: httpResponse.statusCode))
} else {
return Files.moveFile(from: downloadURL, to: destinationURL)
return self.rezipIfNeeded(sourceURL: sourceURL, downloadURL: downloadURL)
.flatMap(.concat) { archiveURL -> SignalProducer<URL, CarthageError> in
return Files.moveFile(from: archiveURL, to: destinationURL)
}
}
}
.then(SignalProducer<(), CarthageError>.empty)
}

private func rezipIfNeeded(sourceURL: URL, downloadURL: URL) -> SignalProducer<URL, CarthageError> {
guard Archive.hasTarExtension(fileURL: sourceURL) else {
return SignalProducer<URL, CarthageError>(value: downloadURL)
}

// Untar and zip again
let tempURL = downloadURL.deletingLastPathComponent().appendingPathComponent(sourceURL.lastPathComponent)
return Files.moveFile(from: downloadURL, to: tempURL)
.flatMap(.concat) { Archive.unarchive(archive: $0) }
.flatMap(.concat) { directoryURL -> SignalProducer<URL, CarthageError> in
let zipArchiveFileName = "archive.zip"
let zipArchiveURL = directoryURL.appendingPathComponent(zipArchiveFileName)
return Archive.zip(paths: ["."], into: zipArchiveURL, workingDirectoryURL: directoryURL)
}
}
}

final class GitHubBinariesCache: AbstractBinariesCache {
Expand Down

0 comments on commit 8c7e16a

Please sign in to comment.