diff --git a/packages/mongodb-memory-server-core/src/util/MongoBinary.ts b/packages/mongodb-memory-server-core/src/util/MongoBinary.ts index 883def962..39d539fb2 100644 --- a/packages/mongodb-memory-server-core/src/util/MongoBinary.ts +++ b/packages/mongodb-memory-server-core/src/util/MongoBinary.ts @@ -1,10 +1,9 @@ import os from 'os'; -import path from 'path'; import MongoBinaryDownload from './MongoBinaryDownload'; import resolveConfig, { envToBool, ResolveConfigVariables } from './resolveConfig'; import debug from 'debug'; import * as semver from 'semver'; -import { assertion, isNullOrUndefined, mkdir } from './utils'; +import { assertion, isNullOrUndefined, lockfilePath, mkdir } from './utils'; import { spawnSync } from 'child_process'; import { LockFile } from './lockfile'; import { DryMongoBinary, BaseDryMongoBinaryOptions } from './DryMongoBinary'; @@ -31,7 +30,7 @@ export class MongoBinary { await mkdir(downloadDir); /** Lockfile path */ - const lockfile = path.resolve(downloadDir, `${version}.lock`); + const lockfile = lockfilePath(downloadDir, version); log(`download: Waiting to acquire Download lock for file "${lockfile}"`); // wait to get a lock // downloading of binaries may be quite long procedure diff --git a/packages/mongodb-memory-server-core/src/util/utils.ts b/packages/mongodb-memory-server-core/src/util/utils.ts index 4867efe7b..bdf56f214 100644 --- a/packages/mongodb-memory-server-core/src/util/utils.ts +++ b/packages/mongodb-memory-server-core/src/util/utils.ts @@ -379,3 +379,13 @@ export function md5(content: BinaryLike): string { export async function md5FromFile(file: string): Promise { return md5(await fspromises.readFile(file)); } + +/** + * Helper function to get the lockfile for the provided `version` in `downloadDir` + * @param downloadDir The Download directory of the binary + * @param version The version to be downlaoded + * @returns The lockfile path + */ +export function lockfilePath(downloadDir: string, version: string): string { + return path.resolve(downloadDir, `${version}.lock`); +}