|
1 | 1 | import { statOrNull, spawn, debug, debug7z } from "./util"
|
2 |
| -import { writeFile, rename, remove } from "fs-extra-p" |
| 2 | +import { writeFile, rename, remove, stat, emptyDir } from "fs-extra-p" |
3 | 3 | import { download } from "./httpRequest"
|
4 | 4 | import { path7za } from "7zip-bin"
|
5 | 5 | import * as path from "path"
|
@@ -41,25 +41,31 @@ async function doDownloadFpm(version: string, osAndArch: string): Promise<string
|
41 | 41 | const cacheDir = path.join(homedir(), ".cache", "fpm")
|
42 | 42 | const fpmDir = path.join(cacheDir, dirName)
|
43 | 43 |
|
44 |
| - const stat = await statOrNull(fpmDir) |
45 |
| - if (stat != null && stat.isDirectory()) { |
| 44 | + const fpmDirStat = await statOrNull(fpmDir) |
| 45 | + if (fpmDirStat != null && fpmDirStat.isDirectory()) { |
46 | 46 | debug(`Found existing fpm ${fpmDir}`)
|
47 | 47 | return path.join(fpmDir, "fpm")
|
48 | 48 | }
|
49 | 49 |
|
50 | 50 | // 7z cannot be extracted from the input stream, temp file is required
|
51 | 51 | const tempName = getTempName()
|
52 |
| - const archiveName = path.join(cacheDir, tempName + ".7z") |
53 |
| - debug(`Download fpm from ${url} to ${archiveName}`) |
54 |
| - await download(url, archiveName) |
| 52 | + const archiveName = path.join(cacheDir, `${tempName}.7z`) |
55 | 53 | const tempUnpackDir = path.join(cacheDir, tempName)
|
56 |
| - const args = ["x", archiveName, "-o" + tempName, "-bd"] |
| 54 | + debug(`Download fpm from ${url} to ${archiveName}`) |
| 55 | + await BluebirdPromise.all<any>([download(url, archiveName), emptyDir(tempUnpackDir)]) |
| 56 | + |
| 57 | + if (debug.enabled && (!(await stat(archiveName)).isFile())) { |
| 58 | + throw new Error(`${archiveName} was not downloaded correctly`) |
| 59 | + } |
| 60 | + |
| 61 | + const args = ["x", archiveName, "-o" + tempUnpackDir, "-bd"] |
57 | 62 | if (debug7z.enabled) {
|
58 | 63 | args.push("-bb3")
|
59 | 64 | }
|
60 | 65 | else if (!debug.enabled) {
|
61 | 66 | args.push("-bb0")
|
62 | 67 | }
|
| 68 | + |
63 | 69 | await spawn(path7za, args, {
|
64 | 70 | cwd: cacheDir,
|
65 | 71 | stdio: ["ignore", debug.enabled ? "inherit" : "ignore", "inherit"],
|
|
0 commit comments