@@ -88,6 +88,7 @@ struct Install: SwiftlyCommand {
8888 }
8989
9090 var config = try await Config . load ( ctx)
91+ let toolchainVersion = try await Self . determineToolchainVersion ( ctx, version: self . version, config: & config)
9192
9293 let ( postInstallScript, pathChanged) = try await Self . execute (
9394 ctx,
@@ -109,12 +110,29 @@ struct Install: SwiftlyCommand {
109110
110111 // Fish doesn't cache its path, so this instruction is not necessary.
111112 if pathChanged && !shell. hasSuffix ( " fish " ) {
112- await ctx. print ( Messages . refreshShell)
113+ await ctx. print (
114+ """
115+ NOTE: Swiftly has updated some elements in your path and your shell may not yet be
116+ aware of the changes. You can update your shell's environment by running
117+
118+ hash -r
119+
120+ or restarting your shell.
121+
122+ """ )
113123 }
114124
115125 if let postInstallScript {
116126 guard let postInstallFile = self . postInstallFile else {
117- throw SwiftlyError ( message: Messages . postInstall ( postInstallScript) )
127+ throw SwiftlyError (
128+ message: """
129+
130+ There are some dependencies that should be installed before using this toolchain.
131+ You can run the following script as the system administrator (e.g. root) to prepare
132+ your system:
133+
134+ \( postInstallScript)
135+ """ )
118136 }
119137
120138 try Data ( postInstallScript. utf8) . write (
@@ -132,21 +150,23 @@ struct Install: SwiftlyCommand {
132150 var pathChanged = false
133151
134152 // Create proxies if we have a location where we can point them
135- if let proxyTo = try ? Swiftly . currentPlatform. findSwiftlyBin ( ctx) {
153+ if let proxyTo = try ? await Swiftly . currentPlatform. findSwiftlyBin ( ctx) {
136154 // Ensure swiftly doesn't overwrite any existing executables without getting confirmation first.
137155 let swiftlyBinDir = Swiftly . currentPlatform. swiftlyBinDir ( ctx)
138156 let swiftlyBinDirContents =
139- ( try ? FileManager . default . contentsOfDirectory ( atPath: swiftlyBinDir. path ) ) ?? [ String] ( )
157+ ( try ? await fs . ls ( atPath: swiftlyBinDir) ) ?? [ String] ( )
140158 let toolchainBinDir = Swiftly . currentPlatform. findToolchainBinDir ( ctx, version)
141- let toolchainBinDirContents = try FileManager . default. contentsOfDirectory (
142- atPath: toolchainBinDir. path)
159+ let toolchainBinDirContents = try await fs. ls ( atPath: toolchainBinDir)
143160
144- let existingProxies = swiftlyBinDirContents. filter { bin in
161+ var existingProxies : [ String ] = [ ]
162+
163+ for bin in swiftlyBinDirContents {
145164 do {
146- let linkTarget = try FileManager . default. destinationOfSymbolicLink (
147- atPath: swiftlyBinDir. appendingPathComponent ( bin) . path)
148- return linkTarget == proxyTo
149- } catch { return false }
165+ let linkTarget = try await fs. readlink ( atPath: swiftlyBinDir / bin)
166+ if linkTarget == proxyTo {
167+ existingProxies. append ( bin)
168+ }
169+ } catch { continue }
150170 }
151171
152172 let overwrite = Set ( toolchainBinDirContents) . subtracting ( existingProxies) . intersection (
@@ -155,7 +175,7 @@ struct Install: SwiftlyCommand {
155175 await ctx. print ( " The following existing executables will be overwritten: " )
156176
157177 for executable in overwrite {
158- await ctx. print ( " \( swiftlyBinDir. appendingPathComponent ( executable) . path ) " )
178+ await ctx. print ( " \( swiftlyBinDir / executable) " )
159179 }
160180
161181 guard await ctx. promptForConfirmation ( defaultBehavior: false ) else {
@@ -171,16 +191,13 @@ struct Install: SwiftlyCommand {
171191 overwrite)
172192
173193 for p in proxiesToCreate {
174- let proxy = Swiftly . currentPlatform. swiftlyBinDir ( ctx) . appendingPathComponent ( p )
194+ let proxy = Swiftly . currentPlatform. swiftlyBinDir ( ctx) / p
175195
176- if proxy . fileExists ( ) {
177- try FileManager . default . removeItem ( at : proxy)
196+ if try await fs . exists ( atPath : proxy ) {
197+ try await fs . remove ( atPath : proxy)
178198 }
179199
180- try FileManager . default. createSymbolicLink (
181- atPath: proxy. path,
182- withDestinationPath: proxyTo
183- )
200+ try await fs. symlink ( atPath: proxy, linkPath: proxyTo)
184201
185202 pathChanged = true
186203 }
@@ -330,120 +347,15 @@ struct Install: SwiftlyCommand {
330347
331348 try await Swiftly . currentPlatform. install ( ctx, from: tmpFile, version: version, verbose: verbose)
332349
333- var pathChanged = false
334-
335- // Create proxies if we have a location where we can point them
336- if let proxyTo = try ? await Swiftly . currentPlatform. findSwiftlyBin( ctx) {
337- // Ensure swiftly doesn't overwrite any existing executables without getting confirmation first.
338- let swiftlyBinDir = Swiftly . currentPlatform. swiftlyBinDir ( ctx)
339- let swiftlyBinDirContents =
340- ( try ? await fs. ls ( atPath: swiftlyBinDir) ) ?? [ String] ( )
341- let toolchainBinDir = Swiftly . currentPlatform. findToolchainBinDir ( ctx, version)
342- let toolchainBinDirContents = try await fs. ls ( atPath: toolchainBinDir)
343-
344- var existingProxies : [ String ] = [ ]
345-
346- for bin in swiftlyBinDirContents {
347- do {
348- let linkTarget = try await fs. readlink ( atPath: swiftlyBinDir / bin)
349- if linkTarget == proxyTo {
350- existingProxies. append ( bin)
351- }
352- } catch { continue }
353- }
354-
355- let overwrite = Set ( toolchainBinDirContents) . subtracting ( existingProxies) . intersection (
356- swiftlyBinDirContents)
357- if !overwrite. isEmpty && !assumeYes {
358- await ctx. print ( " The following existing executables will be overwritten: " )
359-
360- for executable in overwrite {
361- await ctx. print ( " \( swiftlyBinDir / executable) " )
362- }
363-
364- <<<<<<< HEAD
365- guard await ctx. promptForConfirmation ( defaultBehavior: false ) else {
366- throw SwiftlyError ( message: " Toolchain installation has been cancelled " )
367- }
368- }
369-
370- if verbose {
371- await ctx. print ( " Setting up toolchain proxies... " )
372- }
373-
374- let proxiesToCreate = Set ( toolchainBinDirContents) . subtracting ( swiftlyBinDirContents) . union (
375- overwrite)
376-
377- for p in proxiesToCreate {
378- let proxy = Swiftly . currentPlatform. swiftlyBinDir ( ctx) / p
379-
380- if try await fs. exists ( atPath: proxy) {
381- try await fs. remove ( atPath: proxy)
382- }
383-
384- try await fs. symlink ( atPath: proxy, linkPath: proxyTo)
385-
386- pathChanged = true
387- }
388- }
389-
390- config. installedToolchains. insert ( version)
391-
392- =======
393- let do wnloadedMiB = Double ( progress. receivedBytes) / ( 1024.0 * 1024.0 )
394- let totalMiB = Double ( progress. totalBytes!) / ( 1024.0 * 1024.0 )
395-
396- lastUpdate = Date ( )
397-
398- animation. update (
399- step: progress. receivedBytes,
400- total: progress. totalBytes!,
401- text:
402- " Downloaded \( String ( format: " %.1f " , downloadedMiB) ) MiB of \( String ( format: " %.1f " , totalMiB) ) MiB "
403- )
404- }
405- )
406- } catch let notFound as DownloadNotFoundError {
407- throw SwiftlyError ( message: " \( version) does not exist at URL \( notFound. url) , exiting " )
408- } catch {
409- animation. complete ( success: false )
410- throw error
411- }
412- animation. complete ( success: true )
413-
414- if verifySignature {
415- try await Swiftly . currentPlatform. verifyToolchainSignature (
350+ let pathChanged = try await Self . setupProxies (
416351 ctx,
417- toolchainFile : toolchainFile ,
418- archive : tmpFile ,
419- verbose : verbose
352+ version : version ,
353+ verbose : verbose ,
354+ assumeYes : assumeYes
420355 )
421- }
422-
423- try await Swiftly. currentPlatform. install ( ctx, from: tmpFile, version: version, verbose: verbose)
424-
425- let pathChanged = try await Self . setupProxies (
426- ctx,
427- version: version,
428- verbose: verbose,
429- assumeYes: assumeYes
430- )
431-
432- config. installedToolchains. insert ( version)
433356
434- try config. save ( ctx)
435-
436- // If this is the first installed toolchain, mark it as in-use regardless of whether the
437- // --use argument was provided.
438- if useInstalledToolchain {
439- try await Use . execute ( ctx, version, globalDefault: false , & config)
440- }
357+ config. installedToolchains. insert ( version)
441358
442- // We always update the global default toolchain if there is none set. This could
443- // be the only toolchain that is installed, which makes it the only choice.
444- if config. inUse == nil {
445- config. inUse = version
446- >>>>>>> 5 d7 eb2 d ( Add ability to temporarily disable swiftly)
447359 try config. save ( ctx)
448360
449361 // If this is the first installed toolchain, mark it as in-use regardless of whether the
0 commit comments