@@ -5,7 +5,7 @@ import { type ExecaError, execa } from "execa"
55import which from "which"
66import { addAptKeyViaServer } from "./apt-key.js"
77import { isAptPackInstalled } from "./is-installed.js"
8- import { updateRepos } from "./update.js"
8+ import { updateAptRepos } from "./update.js"
99
1010/**
1111 * The information about an installation result
@@ -63,7 +63,7 @@ export async function installAptPack(packages: AptPackage[], update = false): Pr
6363
6464 // Update the repos if needed
6565 if ( update ) {
66- updateRepos ( apt )
66+ updateAptRepos ( apt )
6767 didUpdate = true
6868 }
6969
@@ -85,15 +85,18 @@ export async function installAptPack(packages: AptPackage[], update = false): Pr
8585
8686 // Install
8787 try {
88- execRootSync ( apt , [ "install" , "--fix-broken" , "-y" , ...needToInstall ] , { ...defaultExecOptions , env : getEnv ( apt ) } )
88+ execRootSync ( apt , [ "install" , "--fix-broken" , "-y" , ...needToInstall ] , {
89+ ...defaultExecOptions ,
90+ env : getAptEnv ( apt ) ,
91+ } )
8992 } catch ( err ) {
9093 if ( isExecaError ( err ) ) {
9194 if ( retryErrors . some ( ( error ) => err . stderr . includes ( error ) ) ) {
9295 warning ( `Failed to install packages ${ needToInstall } . Retrying...` )
9396 execRootSync (
9497 apt ,
9598 [ "install" , "--fix-broken" , "-y" , "-o" , aptTimeout , ...needToInstall ] ,
96- { ...defaultExecOptions , env : getEnv ( apt ) } ,
99+ { ...defaultExecOptions , env : getAptEnv ( apt ) } ,
97100 )
98101 }
99102 } else {
@@ -134,7 +137,7 @@ export function getApt() {
134137 * @param apt The apt command to use
135138 * @private Used internally
136139 */
137- export function getEnv ( apt : string ) {
140+ export function getAptEnv ( apt : string ) {
138141 const env : NodeJS . ProcessEnv = { ...process . env , DEBIAN_FRONTEND : "noninteractive" }
139142
140143 if ( apt === "nala" ) {
@@ -185,9 +188,9 @@ async function addRepositories(apt: string, packages: AptPackage[]) {
185188 await installAddAptRepo ( apt )
186189 for ( const repo of allRepositories ) {
187190 // eslint-disable-next-line no-await-in-loop
188- execRootSync ( "add-apt-repository" , [ "-y" , "--no-update" , repo ] , { ...defaultExecOptions , env : getEnv ( apt ) } )
191+ execRootSync ( "add-apt-repository" , [ "-y" , "--no-update" , repo ] , { ...defaultExecOptions , env : getAptEnv ( apt ) } )
189192 }
190- updateRepos ( apt )
193+ updateAptRepos ( apt )
191194 didUpdate = true
192195 }
193196}
@@ -198,15 +201,15 @@ async function aptPackageType(apt: string, name: string, version: string | undef
198201 "search" ,
199202 "--names-only" ,
200203 `^${ escapeRegex ( name ) } -${ escapeRegex ( version ) } $` ,
201- ] , { env : getEnv ( apt ) , stdio : "pipe" } )
204+ ] , { env : getAptEnv ( apt ) , stdio : "pipe" } )
202205 if ( stdout . trim ( ) !== "" ) {
203206 return AptPackageType . NameDashVersion
204207 }
205208
206209 try {
207210 // check if apt-get show can find the version
208211 // eslint-disable-next-line @typescript-eslint/no-shadow
209- const { stdout } = await execa ( "apt-cache" , [ "show" , `${ name } =${ version } ` ] , { env : getEnv ( apt ) } )
212+ const { stdout } = await execa ( "apt-cache" , [ "show" , `${ name } =${ version } ` ] , { env : getAptEnv ( apt ) } )
210213 if ( stdout . trim ( ) === "" ) {
211214 return AptPackageType . NameEqualsVersion
212215 }
@@ -216,7 +219,7 @@ async function aptPackageType(apt: string, name: string, version: string | undef
216219 }
217220
218221 try {
219- const { stdout : showStdout } = await execa ( "apt-cache" , [ "show" , name ] , { env : getEnv ( apt ) , stdio : "pipe" } )
222+ const { stdout : showStdout } = await execa ( "apt-cache" , [ "show" , name ] , { env : getAptEnv ( apt ) , stdio : "pipe" } )
220223 if ( showStdout . trim ( ) !== "" ) {
221224 return AptPackageType . Name
222225 }
@@ -226,7 +229,7 @@ async function aptPackageType(apt: string, name: string, version: string | undef
226229
227230 // If apt-cache fails, update the repos and try again
228231 if ( ! didUpdate ) {
229- updateRepos ( getApt ( ) )
232+ updateAptRepos ( getApt ( ) )
230233 didUpdate = true
231234 return aptPackageType ( apt , name , version )
232235 }
@@ -258,15 +261,15 @@ async function installAddAptRepo(apt: string) {
258261 execRootSync (
259262 apt ,
260263 [ "install" , "-y" , "--fix-broken" , "-o" , aptTimeout , "software-properties-common" ] ,
261- { ...defaultExecOptions , env : getEnv ( apt ) } ,
264+ { ...defaultExecOptions , env : getAptEnv ( apt ) } ,
262265 )
263266}
264267
265268/** Install gnupg and certificates (usually missing from docker containers) */
266269async function initApt ( apt : string ) {
267270 // Update the repos if needed
268271 if ( ! didUpdate ) {
269- updateRepos ( apt )
272+ updateAptRepos ( apt )
270273 didUpdate = true
271274 }
272275
@@ -279,7 +282,7 @@ async function initApt(apt: string) {
279282 if ( toInstall . length !== 0 ) {
280283 execRootSync ( apt , [ "install" , "-y" , "--fix-broken" , "-o" , aptTimeout , ...toInstall ] , {
281284 ...defaultExecOptions ,
282- env : getEnv ( apt ) ,
285+ env : getAptEnv ( apt ) ,
283286 } )
284287 }
285288
0 commit comments