( job: BinaryDownloadJob, nativePlatform: string, version: string, )
| 243 | } |
| 244 | |
| 245 | async function binaryNeedsToBeDownloaded( |
| 246 | job: BinaryDownloadJob, |
| 247 | nativePlatform: string, |
| 248 | version: string, |
| 249 | ): Promise<boolean> { |
| 250 | // If there is an ENV Override and the file exists then it does not need to be downloaded |
| 251 | if (job.envVarPath && fs.existsSync(job.envVarPath)) { |
| 252 | return false |
| 253 | } |
| 254 | // 1. Check if file exists |
| 255 | const targetExists = await exists(job.targetFilePath) |
| 256 | // 2. If exists, check, if cached file exists and is up to date and has same hash as file. |
| 257 | // If not, copy cached file over |
| 258 | const cachedFile = await getCachedBinaryPath({ |
| 259 | ...job, |
| 260 | version, |
| 261 | }) |
| 262 | |
| 263 | if (cachedFile) { |
| 264 | // for local development, when using `enginesOverride` |
| 265 | // we don't have the sha256 hash, so we can't check it |
| 266 | if (job.skipCacheIntegrityCheck === true) { |
| 267 | await overwriteFile(cachedFile, job.targetFilePath) |
| 268 | |
| 269 | return false |
| 270 | } |
| 271 | |
| 272 | const sha256FilePath = cachedFile + '.sha256' |
| 273 | if (await exists(sha256FilePath)) { |
| 274 | const sha256File = await fs.promises.readFile(sha256FilePath, 'utf-8') |
| 275 | const sha256Cache = await getHash(cachedFile) |
| 276 | if (sha256File === sha256Cache) { |
| 277 | if (!targetExists) { |
| 278 | debug(`copying ${cachedFile} to ${job.targetFilePath}`) |
| 279 | |
| 280 | // TODO Remove when https://github.com/docker/for-linux/issues/1015 is fixed |
| 281 | // Workaround for https://github.com/prisma/prisma/issues/7037 |
| 282 | await fs.promises.utimes(cachedFile, new Date(), new Date()) |
| 283 | |
| 284 | await overwriteFile(cachedFile, job.targetFilePath) |
| 285 | } |
| 286 | const targetSha256 = await getHash(job.targetFilePath) |
| 287 | if (sha256File !== targetSha256) { |
| 288 | debug(`overwriting ${job.targetFilePath} with ${cachedFile} as hashes do not match`) |
| 289 | await overwriteFile(cachedFile, job.targetFilePath) |
| 290 | } |
| 291 | return false |
| 292 | } else { |
| 293 | return true |
| 294 | } |
| 295 | } else if (process.env.PRISMA_ENGINES_CHECKSUM_IGNORE_MISSING) { |
| 296 | debug( |
| 297 | `the checksum file ${sha256FilePath} is missing but this was ignored because the PRISMA_ENGINES_CHECKSUM_IGNORE_MISSING environment variable is set`, |
| 298 | ) |
| 299 | if (targetExists) { |
| 300 | return false |
| 301 | } |
| 302 | if (cachedFile) { |
no test coverage detected