(options: DownloadBinaryOptions)
| 387 | } |
| 388 | |
| 389 | async function downloadBinary(options: DownloadBinaryOptions): Promise<void> { |
| 390 | const { version, progressCb, targetFilePath, downloadUrl } = options |
| 391 | |
| 392 | const targetDir = path.dirname(targetFilePath) |
| 393 | |
| 394 | try { |
| 395 | fs.accessSync(targetDir, fs.constants.W_OK) |
| 396 | await ensureDir(targetDir) |
| 397 | } catch (e) { |
| 398 | if (options.failSilent || (e as NodeJS.ErrnoException).code !== 'EACCES') { |
| 399 | return |
| 400 | } else { |
| 401 | throw new Error(`Can't write to ${targetDir} please make sure you install "prisma" with the right permissions.`) |
| 402 | } |
| 403 | } |
| 404 | |
| 405 | debug(`Downloading ${downloadUrl} to ${targetFilePath} ...`) |
| 406 | |
| 407 | if (progressCb) { |
| 408 | progressCb(0) |
| 409 | } |
| 410 | |
| 411 | const { sha256, zippedSha256 } = await downloadZip(downloadUrl, targetFilePath, progressCb) |
| 412 | if (progressCb) { |
| 413 | progressCb(1) |
| 414 | } |
| 415 | |
| 416 | chmodPlusX(targetFilePath) |
| 417 | |
| 418 | // Cache result |
| 419 | await saveFileToCache(options, version, sha256, zippedSha256) |
| 420 | } |
| 421 | |
| 422 | async function saveFileToCache( |
| 423 | job: BinaryDownloadJob, |
no test coverage detected