Skip to content

Commit

Permalink
fix: do not copy electronDist using hard links
Browse files Browse the repository at this point in the history
  • Loading branch information
develar committed Jun 14, 2017
1 parent 157c730 commit 7519eb4
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
10 changes: 8 additions & 2 deletions docs/api/electron-builder-util.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@

### FileCopier
**Kind**: class of [<code>electron-builder-util/out/fs</code>](#module_electron-builder-util/out/fs)
**Properties**

| Name | Type |
| --- | --- |
| **isUseHardLink**| <code>Boolean</code> |

<a name="module_electron-builder-util/out/fs.FileCopier+copy"></a>

#### `fileCopier.copy(src, dest, stat)` ⇒ <code>Promise&lt;void&gt;</code>
Expand All @@ -117,8 +123,8 @@ Hard links is used if supported and allowed.
| --- | --- |
| src | <code>String</code> |
| destination | <code>String</code> |
| filter | <code>module:electron-builder-util/out/fs.__type</code> |
| transformer | <code>module:electron-builder-util/out/fs.__type</code> |
| filter | <code>module:electron-builder-util/out/fs.__type</code> \| <code>null</code> |
| transformer | <code>module:electron-builder-util/out/fs.__type</code> \| <code>null</code> |
| isUseHardLink | <code>callback</code> |

<a name="module_electron-builder-util/out/fs.copyFile"></a>
Expand Down
14 changes: 9 additions & 5 deletions packages/electron-builder-util/src/fs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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<any> {
export function copyDir(src: string, destination: string, filter?: Filter | null, transformer?: FileTransformer | null, isUseHardLink?: (file: string) => boolean): Promise<any> {
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<string>()
const fileCopier = new FileCopier(isUseHardLink, transformer)
const links: Array<Link> = []
return walk(src, filter, async(file, stat, parent) => {
if (!stat.isFile() && !stat.isSymbolicLink()) {
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions packages/electron-builder/src/packager/dirPackager.ts
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -61,7 +61,7 @@ async function unpack(packager: PlatformPackager<any>, 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") {
Expand Down

0 comments on commit 7519eb4

Please sign in to comment.