11import Foundation
2+ import Subprocess
23import SwiftlyCore
34import SystemPackage
45
@@ -263,7 +264,13 @@ public struct Linux: Platform {
263264 }
264265
265266 if requireSignatureValidation {
266- guard ( try ? self . runProgram ( " gpg " , " --version " , quiet: true ) ) != nil else {
267+ let result = try await run (
268+ . name( " gpg " ) ,
269+ arguments: [ " --version " ] ,
270+ output: . discarded
271+ )
272+
273+ if !result. terminationStatus. isSuccess {
267274 var msg = " gpg is not installed. "
268275 if let manager {
269276 msg += """
@@ -278,7 +285,7 @@ public struct Linux: Platform {
278285 throw SwiftlyError ( message: msg)
279286 }
280287
281- try await importGpgKeys ( ctx)
288+ try await self . importGpgKeys ( ctx)
282289 }
283290
284291 guard let manager = manager else {
@@ -304,7 +311,12 @@ public struct Linux: Platform {
304311 do {
305312 switch manager {
306313 case " apt-get " :
307- if let pkgList = try await self . runProgramOutput ( " dpkg " , " -l " , package ) {
314+ let result = try await run ( . name( " dpkg " ) , arguments: [ " -l " , package ] , output: . string( limit: 100 * 1024 ) )
315+ if !result. terminationStatus. isSuccess {
316+ return false
317+ }
318+
319+ if let pkgList = result. standardOutput {
308320 // The package might be listed but not in an installed non-error state.
309321 //
310322 // Look for something like this:
@@ -318,8 +330,8 @@ public struct Linux: Platform {
318330 }
319331 return false
320332 case " yum " :
321- try self . runProgram ( " yum " , " list " , " installed " , package , quiet : true )
322- return true
333+ let result = try await run ( . name ( " yum " ) , arguments : [ " list " , " installed " , package ] , output : . discarded )
334+ return result . terminationStatus . isSuccess
323335 default :
324336 return true
325337 }
@@ -379,7 +391,15 @@ public struct Linux: Platform {
379391 tmpDir / String( name)
380392 }
381393
382- try self . runProgram ( ( tmpDir / " swiftly " ) . string, " init " )
394+ let config = Configuration (
395+ executable: . path( tmpDir / " swiftly " ) ,
396+ arguments: [ " init " ]
397+ )
398+
399+ let result = try await run ( config, output: . standardOutput, error: . standardError)
400+ if !result. terminationStatus. isSuccess {
401+ throw RunProgramError ( terminationStatus: result. terminationStatus, config: config)
402+ }
383403 }
384404 }
385405
@@ -402,8 +422,8 @@ public struct Linux: Platform {
402422 _ ctx: SwiftlyCoreContext , toolchainFile: ToolchainFile , archive: FilePath , verbose: Bool
403423 ) async throws {
404424 // Ensure GPG keys are imported before attempting signature verification
405- try await importGpgKeys ( ctx)
406-
425+ try await self . importGpgKeys ( ctx)
426+
407427 if verbose {
408428 await ctx. message ( " Downloading toolchain signature... " )
409429 }
@@ -416,11 +436,9 @@ public struct Linux: Platform {
416436 await ctx. message ( " Verifying toolchain signature... " )
417437 do {
418438 if let mockedHomeDir = ctx. mockedHomeDir {
419- var env = ProcessInfo . processInfo. environment
420- env [ " GNUPGHOME " ] = ( mockedHomeDir / " .gnupg " ) . string
421- try await sys. gpg ( ) . verify ( detached_signature: sigFile, signed_data: archive) . run ( self , env: env, quiet: false )
439+ try await sys. gpg ( ) . verify ( detached_signature: sigFile, signed_data: archive) . run ( environment: . inherit. updating ( [ " GNUPGHOME " : ( mockedHomeDir / " .gnupg " ) . string] ) , quiet: false )
422440 } else {
423- try await sys. gpg ( ) . verify ( detached_signature: sigFile, signed_data: archive) . run ( self , quiet: !verbose)
441+ try await sys. gpg ( ) . verify ( detached_signature: sigFile, signed_data: archive) . run ( quiet: !verbose)
424442 }
425443 } catch {
426444 throw SwiftlyError ( message: " Signature verification failed: \( error) . " )
@@ -437,9 +455,9 @@ public struct Linux: Platform {
437455 if let mockedHomeDir = ctx. mockedHomeDir {
438456 var env = ProcessInfo . processInfo. environment
439457 env [ " GNUPGHOME " ] = ( mockedHomeDir / " .gnupg " ) . string
440- try await sys. gpg ( ) . _import ( key: tmpFile) . run ( self , env : env, quiet: true )
458+ try await sys. gpg ( ) . _import ( key: tmpFile) . run ( environment : . init ( env) , quiet: true )
441459 } else {
442- try await sys. gpg ( ) . _import ( key: tmpFile) . run ( self , quiet: true )
460+ try await sys. gpg ( ) . _import ( key: tmpFile) . run ( quiet: true )
443461 }
444462 }
445463 }
@@ -448,8 +466,8 @@ public struct Linux: Platform {
448466 _ ctx: SwiftlyCoreContext , archiveDownloadURL: URL , archive: FilePath , verbose: Bool
449467 ) async throws {
450468 // Ensure GPG keys are imported before attempting signature verification
451- try await importGpgKeys ( ctx)
452-
469+ try await self . importGpgKeys ( ctx)
470+
453471 if verbose {
454472 await ctx. message ( " Downloading swiftly signature... " )
455473 }
@@ -464,11 +482,9 @@ public struct Linux: Platform {
464482 await ctx. message ( " Verifying swiftly signature... " )
465483 do {
466484 if let mockedHomeDir = ctx. mockedHomeDir {
467- var env = ProcessInfo . processInfo. environment
468- env [ " GNUPGHOME " ] = ( mockedHomeDir / " .gnupg " ) . string
469- try await sys. gpg ( ) . verify ( detached_signature: sigFile, signed_data: archive) . run ( self , env: env, quiet: false )
485+ try await sys. gpg ( ) . verify ( detached_signature: sigFile, signed_data: archive) . run ( environment: . inherit. updating ( [ " GNUPGHOME " : ( mockedHomeDir / " .gnupg " ) . string] ) , quiet: false )
470486 } else {
471- try await sys. gpg ( ) . verify ( detached_signature: sigFile, signed_data: archive) . run ( self , quiet: !verbose)
487+ try await sys. gpg ( ) . verify ( detached_signature: sigFile, signed_data: archive) . run ( quiet: !verbose)
472488 }
473489 } catch {
474490 throw SwiftlyError ( message: " Signature verification failed: \( error) . " )
@@ -622,7 +638,7 @@ public struct Linux: Platform {
622638
623639 public func getShell( ) async throws -> String {
624640 let userName = ProcessInfo . processInfo. userName
625- if let entry = try await sys. getent ( database: " passwd " , key: userName) . entries ( self ) . first {
641+ if let entry = try await sys. getent ( database: " passwd " , key: userName) . entries ( ) . first {
626642 if let shell = entry. last { return shell }
627643 }
628644
0 commit comments