From ba9e9da3587a63133d6f1a6d59a6fd7e34edf12a Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Tue, 30 Jan 2018 15:49:05 -0800 Subject: [PATCH] feat(snap): do not all apt-get install and update if build packages already installed So, reduce risk that build will be failed because of sudo. Yes - snapcraft can also install build packages. But at least electron-builder doesn't fail. --- packages/electron-builder-lib/src/targets/snap.ts | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/packages/electron-builder-lib/src/targets/snap.ts b/packages/electron-builder-lib/src/targets/snap.ts index d8013f7cbe8..43faadee6ae 100644 --- a/packages/electron-builder-lib/src/targets/snap.ts +++ b/packages/electron-builder-lib/src/targets/snap.ts @@ -7,6 +7,7 @@ import { Target } from "../core" import { LinuxPackager } from "../linuxPackager" import { LinuxTargetHelper } from "./LinuxTargetHelper" import { createStageDir, StageDir } from "./targetUtil" +import BluebirdPromise from "bluebird-lst" // usr/share/fonts is required, cannot run otherwise const unnecessaryFiles = [ @@ -110,8 +111,14 @@ export default class SnapTarget extends Target { } else { if (options.buildPackages != null && options.buildPackages.length > 0) { - await spawn("apt-get", ["-qq", "update"]) - await spawn("apt-get", ["-qq", "install", "--no-install-recommends"].concat(options.buildPackages)) + const notInstalledPackages = await BluebirdPromise.filter(options.buildPackages, (it): Promise => { + return exec("dpkg", ["-s", it]) + .then(result => result.includes("is not installed")) + }) + if (notInstalledPackages.length > 0) { + await spawn("apt-get", ["-qq", "update"]) + await spawn("apt-get", ["-qq", "install", "--no-install-recommends"].concat(notInstalledPackages)) + } } const spawnOptions = { cwd: stageDir.dir, @@ -156,4 +163,4 @@ export default class SnapTarget extends Target { stdio: ["ignore", "inherit", "inherit"], }) } -} +} \ No newline at end of file