From 7519eb4d90e5d00114d7028f0ccdeda7b7bcf324 Mon Sep 17 00:00:00 2001 From: develar Date: Wed, 14 Jun 2017 08:27:14 +0200 Subject: [PATCH] fix: do not copy electronDist using hard links Close #1670 --- docs/api/electron-builder-util.md | 10 ++++++++-- packages/electron-builder-util/src/fs.ts | 14 +++++++++----- .../electron-builder/src/packager/dirPackager.ts | 4 ++-- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/docs/api/electron-builder-util.md b/docs/api/electron-builder-util.md index 85390f97d3f..a28c3a4c6e7 100644 --- a/docs/api/electron-builder-util.md +++ b/docs/api/electron-builder-util.md @@ -94,6 +94,12 @@ ### FileCopier **Kind**: class of [electron-builder-util/out/fs](#module_electron-builder-util/out/fs) +**Properties** + +| Name | Type | +| --- | --- | +| **isUseHardLink**| Boolean | + #### `fileCopier.copy(src, dest, stat)` ⇒ Promise<void> @@ -117,8 +123,8 @@ Hard links is used if supported and allowed. | --- | --- | | src | String | | destination | String | -| filter | module:electron-builder-util/out/fs.__type | -| transformer | module:electron-builder-util/out/fs.__type | +| filter | module:electron-builder-util/out/fs.__type \| null | +| transformer | module:electron-builder-util/out/fs.__type \| null | | isUseHardLink | callback | diff --git a/packages/electron-builder-util/src/fs.ts b/packages/electron-builder-util/src/fs.ts index fb93f9d4c51..50a72960f00 100644 --- a/packages/electron-builder-util/src/fs.ts +++ b/packages/electron-builder-util/src/fs.ts @@ -159,9 +159,10 @@ export function copyOrLinkFile(src: string, dest: string, stats?: Stats | null, } export class FileCopier { - private isUseHardLink = _isUseHardLink + isUseHardLink: boolean - constructor(private readonly isUseHardLinkFunction?: (file: string) => boolean, private readonly transformer?: FileTransformer) { + constructor(private readonly isUseHardLinkFunction?: (file: string) => boolean, private readonly transformer?: FileTransformer | null) { + this.isUseHardLink = _isUseHardLink && isUseHardLinkFunction !== DO_NOT_USE_HARD_LINKS } async copy(src: string, dest: string, stat: Stats | undefined) { @@ -203,13 +204,14 @@ export class FileCopier { * Empty directories is never created. * Hard links is used if supported and allowed. */ -export function copyDir(src: string, destination: string, filter?: Filter, transformer?: FileTransformer, isUseHardLink?: (file: string) => boolean): Promise { +export function copyDir(src: string, destination: string, filter?: Filter | null, transformer?: FileTransformer | null, isUseHardLink?: (file: string) => boolean): Promise { + const fileCopier = new FileCopier(isUseHardLink, transformer) + if (debug.enabled) { - debug(`Copying ${src} to ${destination}${_isUseHardLink ? " using hard links" : ""}`) + debug(`Copying ${src} to ${destination}${fileCopier.isUseHardLink ? " using hard links" : ""}`) } const createdSourceDirs = new Set() - const fileCopier = new FileCopier(isUseHardLink, transformer) const links: Array = [] return walk(src, filter, async(file, stat, parent) => { if (!stat.isFile() && !stat.isSymbolicLink()) { @@ -232,6 +234,8 @@ export function copyDir(src: string, destination: string, filter?: Filter, trans .then(() => BluebirdPromise.map(links, it => symlink(it.link, it.file), CONCURRENCY)) } +export const DO_NOT_USE_HARD_LINKS = (file: string) => false + interface Link { readonly link: string, readonly file: string diff --git a/packages/electron-builder/src/packager/dirPackager.ts b/packages/electron-builder/src/packager/dirPackager.ts index 7fb797b454c..f76a9bde598 100644 --- a/packages/electron-builder/src/packager/dirPackager.ts +++ b/packages/electron-builder/src/packager/dirPackager.ts @@ -1,7 +1,7 @@ import { path7za } from "7zip-bin" import BluebirdPromise from "bluebird-lst" import { debug7zArgs, spawn } from "electron-builder-util" -import { copyDir } from "electron-builder-util/out/fs" +import { copyDir, DO_NOT_USE_HARD_LINKS } from "electron-builder-util/out/fs" import { log, warn } from "electron-builder-util/out/log" import { chmod, emptyDir } from "fs-extra-p" import * as path from "path" @@ -61,7 +61,7 @@ async function unpack(packager: PlatformPackager, out: string, platform: st const destination = packager.getElectronDestDir(out) log(`Copying Electron from "${source}" to "${destination}"`) await emptyDir(out) - await copyDir(source, destination) + await copyDir(source, destination, null, null, DO_NOT_USE_HARD_LINKS) } if (platform === "linux") {