Skip to content

Commit a93caaa

Browse files
committed
fix: wait for apt lock if it is held
1 parent 7e559c0 commit a93caaa

File tree

7 files changed

+25
-22
lines changed

7 files changed

+25
-22
lines changed

dist/actions/setup-cpp.js

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/actions/setup-cpp.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/legacy/setup-cpp.js

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/legacy/setup-cpp.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/modern/setup-cpp.js

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/modern/setup-cpp.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/utils/setup/setupAptPack.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ import type { InstallationInfo } from "./setupBin"
1313
let didUpdate: boolean = false
1414
let didInit: boolean = false
1515

16+
// wait up to 300 seconds if the apt-get lock is held
17+
const aptTimeout = "DPkg::Lock::Timeout=300"
18+
1619
export type AptPackage = {
1720
name: string
1821
version?: string
@@ -65,7 +68,7 @@ export async function setupAptPack(packages: AptPackage[], update = false): Prom
6568
const stderr = (err as ExecaError).stderr
6669
if (retryErrors.some((error) => stderr.includes(error))) {
6770
warning(`Failed to install packages ${needToInstall}. Retrying...`)
68-
execRootSync(apt, ["install", "--fix-broken", "-y", ...needToInstall])
71+
execRootSync(apt, ["install", "--fix-broken", "-y", "-o", aptTimeout, ...needToInstall])
6972
}
7073
} else {
7174
throw err
@@ -104,10 +107,10 @@ async function addRepositories(apt: string, packages: AptPackage[]) {
104107
await initApt(apt)
105108
didInit = true
106109
}
107-
await installAddAptRepo()
110+
await installAddAptRepo(apt)
108111
for (const repo of allRepositories) {
109112
// eslint-disable-next-line no-await-in-loop
110-
execRootSync("add-apt-repository", ["-y", repo])
113+
execRootSync("add-apt-repository", ["-y", "--no-update", repo])
111114
}
112115
updateRepos(apt)
113116
didUpdate = true
@@ -185,14 +188,14 @@ function getApt() {
185188
}
186189

187190
function updateRepos(apt: string) {
188-
execRootSync(apt, apt !== "nala" ? ["update", "-y"] : ["update"])
191+
execRootSync(apt, apt !== "nala" ? ["update", "-y", "-o", aptTimeout] : ["update", "-o", aptTimeout])
189192
}
190193

191-
async function installAddAptRepo() {
194+
async function installAddAptRepo(apt: string) {
192195
if (await isPackageInstalled("software-properties-common")) {
193196
return
194197
}
195-
execRootSync("apt-get", ["install", "-y", "--fix-broken", "software-properties-common"])
198+
execRootSync(apt, ["install", "-y", "--fix-broken", "-o", aptTimeout, "software-properties-common"])
196199
}
197200

198201
/** Install gnupg and certificates (usually missing from docker containers) */
@@ -210,7 +213,7 @@ async function initApt(apt: string) {
210213
])
211214

212215
if (toInstall.length !== 0) {
213-
execRootSync(apt, ["install", "-y", "--fix-broken", ...toInstall])
216+
execRootSync(apt, ["install", "-y", "--fix-broken", "-o", aptTimeout, ...toInstall])
214217
}
215218

216219
const promises: Promise<string | void>[] = [

0 commit comments

Comments
 (0)