@@ -290,7 +290,15 @@ public final class XcodeInstaller {
290290
291291 private func downloadXcode( version: Version , dataSource: DataSource , downloader: Downloader , willInstall: Bool ) -> Promise < ( Xcode , URL ) > {
292292 return firstly { ( ) -> Promise < Version > in
293- loginIfNeeded ( ) . map { version }
293+ if dataSource == . apple {
294+ return loginIfNeeded ( ) . map { version }
295+ } else {
296+ guard let xcode = self . xcodeList. availableXcodes. first ( withVersion: version) else {
297+ throw Error . unavailableVersion ( version)
298+ }
299+
300+ return validateADCSession ( path: xcode. downloadPath) . map { version }
301+ }
294302 }
295303 . then { version -> Promise < Version > in
296304 if self . xcodeList. shouldUpdate {
@@ -300,14 +308,6 @@ public final class XcodeInstaller {
300308 return Promise . value ( version)
301309 }
302310 }
303- . then { version -> Promise < Version > in
304- // This request would've already been made if the Apple data source were being used.
305- // That's not the case for the Xcode Releases data source.
306- // We need the cookies from its response in order to download Xcodes though,
307- // so perform it here first just to be sure.
308- Current . network. dataTask ( with: URLRequest . downloads)
309- . map { _ in version }
310- }
311311 . then { version -> Promise < ( Xcode , URL ) > in
312312 guard let xcode = self . xcodeList. availableXcodes. first ( withVersion: version) else {
313313 throw Error . unavailableVersion ( version)
@@ -337,7 +337,11 @@ public final class XcodeInstaller {
337337 . map { return ( xcode, $0) }
338338 }
339339 }
340-
340+
341+ func validateADCSession( path: String ) -> Promise < Void > {
342+ return Current . network. dataTask ( with: URLRequest . downloadADCAuth ( path: path) ) . asVoid ( )
343+ }
344+
341345 func loginIfNeeded( withUsername providedUsername: String ? = nil , shouldPromptForPassword: Bool = false ) -> Promise < Void > {
342346 return firstly { ( ) -> Promise < Void > in
343347 return Current . network. validateSession ( )
@@ -645,11 +649,15 @@ public final class XcodeInstaller {
645649 }
646650
647651 func update( dataSource: DataSource ) -> Promise < [ Xcode ] > {
648- return firstly { ( ) -> Promise < Void > in
649- loginIfNeeded ( )
650- }
651- . then { ( ) -> Promise < [ Xcode ] > in
652- self . xcodeList. update ( dataSource: dataSource)
652+ if dataSource == . apple {
653+ return firstly { ( ) -> Promise < Void > in
654+ loginIfNeeded ( )
655+ }
656+ . then { ( ) -> Promise < [ Xcode ] > in
657+ self . xcodeList. update ( dataSource: dataSource)
658+ }
659+ } else {
660+ return self . xcodeList. update ( dataSource: dataSource)
653661 }
654662 }
655663
0 commit comments