@@ -30,18 +30,17 @@ final class GithubPackageManager: PackageManagerProtocol {
3030 }
3131
3232 func install( method: InstallationMethod ) async throws {
33- guard case . standardPackage( let source) = method else {
34- throw PackageManagerError . invalidConfiguration
35- }
36-
37- let packagePath = installationDirectory. appending ( path: source. entryName)
38- try await initialize ( in: packagePath)
39-
4033 switch method {
4134 case let . binaryDownload( source, url) :
35+ let packagePath = installationDirectory. appending ( path: source. entryName)
36+ try await initialize ( in: packagePath)
4237 try await downloadBinary ( source, url)
38+
4339 case let . sourceBuild( source, command) :
40+ let packagePath = installationDirectory. appending ( path: source. entryName)
41+ try await initialize ( in: packagePath)
4442 try await installFromSource ( source, command)
43+
4544 case . standardPackage, . unknown:
4645 throw PackageManagerError . invalidConfiguration
4746 }
@@ -64,11 +63,29 @@ final class GithubPackageManager: PackageManagerProtocol {
6463 }
6564
6665 private func downloadBinary( _ source: PackageSource , _ url: URL ) async throws {
67- _ = try await URLSession . shared. data ( from: url)
66+ let ( data, response) = try await URLSession . shared. data ( from: url)
67+
68+ guard let httpResponse = response as? HTTPURLResponse ,
69+ ( 200 ... 299 ) . contains ( httpResponse. statusCode) else {
70+ throw RegistryManagerError . downloadFailed (
71+ url: url,
72+ error: NSError ( domain: " HTTP error " , code: ( response as? HTTPURLResponse ) ? . statusCode ?? - 1 )
73+ )
74+ }
75+
6876 let fileName = url. lastPathComponent
6977 let downloadPath = installationDirectory. appending ( path: source. entryName)
7078 let packagePath = downloadPath. appending ( path: fileName)
7179
80+ do {
81+ try data. write ( to: packagePath, options: . atomic)
82+ } catch {
83+ throw RegistryManagerError . downloadFailed (
84+ url: url,
85+ error: error
86+ )
87+ }
88+
7289 if !FileManager. default. fileExists ( atPath: packagePath. path) {
7390 throw RegistryManagerError . downloadFailed (
7491 url: url,
@@ -84,7 +101,11 @@ final class GithubPackageManager: PackageManagerProtocol {
84101 private func installFromSource( _ source: PackageSource , _ command: String ) async throws {
85102 let installPath = installationDirectory. appending ( path: source. entryName, directoryHint: . isDirectory)
86103 do {
87- _ = try await executeInDirectory ( in: installPath. path, [ " git " , " clone " , source. repositoryUrl!] )
104+ guard let repoURL = source. repositoryUrl else {
105+ throw PackageManagerError . invalidConfiguration
106+ }
107+
108+ _ = try await executeInDirectory ( in: installPath. path, [ " git " , " clone " , repoURL] )
88109 let repoPath = installPath. appending ( path: source. pkgName, directoryHint: . isDirectory)
89110 _ = try await executeInDirectory ( in: repoPath. path, [ command] )
90111 } catch {
0 commit comments