-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(nsis): use name instead of product name as inst dir
- Loading branch information
Showing
12 changed files
with
86 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,75 +1,90 @@ | ||
import { tmpdir } from "os" | ||
import { remove, mkdirs, removeSync } from "fs-extra-p" | ||
import { remove, mkdirs, removeSync, mkdtemp } from "fs-extra-p" | ||
import * as path from "path" | ||
import { getTempName } from "./util" | ||
import BluebirdPromise from "bluebird-lst-c" | ||
import { warn } from "./log" | ||
|
||
const mkdtemp: any | null = require("fs-extra-p").mkdtemp | ||
import { all } from "./promise" | ||
|
||
process.setMaxListeners(30) | ||
|
||
export class TmpDir { | ||
private tmpFileCounter = 0 | ||
private tempDirectoryPromise: Promise<string> | ||
|
||
private dir: string | null | ||
let tempDirPromise: Promise<string> | null | ||
let tempDir: string | null | ||
|
||
getTempFile(suffix: string | null): Promise<string> { | ||
if (this.tempDirectoryPromise == null) { | ||
let promise: Promise<string> | ||
if (mkdtemp == null) { | ||
const dir = path.join(tmpdir(), getTempName("electron-builder")) | ||
promise = mkdirs(dir, {mode: 448}).then(() => dir) | ||
} | ||
else { | ||
promise = mkdtemp(`${path.join(process.env.TEST_DIR || tmpdir(), "electron-builder")}-`) | ||
} | ||
function getTempDir() { | ||
if (tempDirPromise == null) { | ||
let promise: Promise<string> | ||
const systemTmpDir = process.env.TEST_DIR || tmpdir() | ||
if (mkdtemp == null) { | ||
const dir = path.join(systemTmpDir, getTempName("electron-builder")) | ||
promise = mkdirs(dir, {mode: 448}).then(() => dir) | ||
} | ||
else { | ||
promise = mkdtemp(`${path.join(systemTmpDir, "electron-builder")}-`) | ||
} | ||
|
||
this.tempDirectoryPromise = promise | ||
.then(dir => { | ||
this.dir = dir | ||
const cleanup = () => { | ||
if (this.dir == null) { | ||
return | ||
} | ||
tempDirPromise = promise | ||
.then(dir => { | ||
tempDir = dir | ||
const cleanup = () => { | ||
if (tempDir == null) { | ||
return | ||
} | ||
|
||
this.dir = null | ||
try { | ||
removeSync(dir) | ||
} | ||
catch (e) { | ||
if (e.code !== "EPERM") { | ||
warn(`Cannot delete temporary dir "${dir}": ${(e.stack || e).toString()}`) | ||
} | ||
tempDir = null | ||
try { | ||
removeSync(dir) | ||
} | ||
catch (e) { | ||
if (e.code !== "EPERM") { | ||
warn(`Cannot delete temporary dir "${dir}": ${(e.stack || e).toString()}`) | ||
} | ||
} | ||
process.on("exit", cleanup) | ||
process.on("uncaughtException", cleanup) | ||
process.on("SIGINT", cleanup) | ||
return dir | ||
}) | ||
} | ||
process.on("exit", cleanup) | ||
process.on("uncaughtException", cleanup) | ||
process.on("SIGINT", cleanup) | ||
return dir | ||
}) | ||
} | ||
|
||
return tempDirPromise | ||
} | ||
|
||
let tmpFileCounter = 0 | ||
|
||
export class TmpDir { | ||
private tempPrefixPromise: Promise<string> | null | ||
private tempFiles: Array<string> = [] | ||
|
||
getTempFile(suffix: string): Promise<string> { | ||
if (this.tempPrefixPromise == null) { | ||
this.tempPrefixPromise = getTempDir().then(it => path.join(it, (tmpFileCounter++).toString(16))) | ||
} | ||
|
||
return this.tempDirectoryPromise | ||
.then(it => suffix == null ? it : path.join(it, `t-${process.pid.toString(16)}-${(this.tmpFileCounter++).toString(16)}${suffix.startsWith(".") ? suffix : `-${suffix}`}`)) | ||
return this.tempPrefixPromise | ||
.then(it => { | ||
const result = `${it}-${(tmpFileCounter++).toString(16)}${suffix.length === 0 || suffix.startsWith(".") ? suffix : `-${suffix}`}` | ||
this.tempFiles.push(result) | ||
return result | ||
}) | ||
} | ||
|
||
cleanup(): Promise<any> { | ||
const dir = this.dir | ||
if (dir == null) { | ||
const tempFiles = this.tempFiles | ||
if (tempFiles.length === 0) { | ||
return BluebirdPromise.resolve() | ||
} | ||
|
||
this.dir = null | ||
return remove(dir) | ||
this.tempFiles = [] | ||
this.tempPrefixPromise = null | ||
|
||
return all(tempFiles.map(it => remove(it) | ||
.catch(e => { | ||
if (e.code === "EPERM") { | ||
this.dir = dir | ||
} | ||
else { | ||
warn(`Cannot delete temporary dir "${dir}": ${(e.stack || e).toString()}`) | ||
if (e.code !== "EPERM") { | ||
warn(`Cannot delete temporary dir "${it}": ${(e.stack || e).toString()}`) | ||
} | ||
}) | ||
)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1363,9 +1363,9 @@ from@~0: | |
version "0.1.3" | ||
resolved "https://registry.yarnpkg.com/from/-/from-0.1.3.tgz#ef63ac2062ac32acf7862e0d40b44b896f22f3bc" | ||
|
||
fs-extra-p@^3.0.2: | ||
version "3.0.2" | ||
resolved "https://registry.yarnpkg.com/fs-extra-p/-/fs-extra-p-3.0.2.tgz#074e44ca8ae535fe6999458458ff2eb7c956d0c8" | ||
fs-extra-p@^3.0.2, fs-extra-p@^3.0.3: | ||
version "3.0.3" | ||
resolved "https://registry.yarnpkg.com/fs-extra-p/-/fs-extra-p-3.0.3.tgz#2e48b1e6c196feb75ac6f0c6419760ce8b847f33" | ||
dependencies: | ||
bluebird-lst-c "^1.0.5" | ||
fs-extra "^1.0.0" | ||
|
@@ -3422,8 +3422,8 @@ [email protected]: | |
resolved "https://registry.yarnpkg.com/throttleit/-/throttleit-0.0.2.tgz#cfedf88e60c00dd9697b61fdd2a8343a9b680eaf" | ||
|
||
through2@^2.0.0, through2@^2.0.2, through2@~2.0.0: | ||
version "2.0.2" | ||
resolved "https://registry.yarnpkg.com/through2/-/through2-2.0.2.tgz#316d3a4f444af641496aa7f45a713be72576baf4" | ||
version "2.0.3" | ||
resolved "https://registry.yarnpkg.com/through2/-/through2-2.0.3.tgz#0004569b37c7c74ba39c43f3ced78d1ad94140be" | ||
dependencies: | ||
readable-stream "^2.1.5" | ||
xtend "~4.0.1" | ||
|