Skip to content

Commit 9db479f

Browse files
committed
refactor(utils): add function "lockfilePath"
and use it in "MongoBinary"
1 parent fe56c0a commit 9db479f

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

packages/mongodb-memory-server-core/src/util/MongoBinary.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import os from 'os';
2-
import path from 'path';
32
import MongoBinaryDownload from './MongoBinaryDownload';
43
import resolveConfig, { envToBool, ResolveConfigVariables } from './resolveConfig';
54
import debug from 'debug';
65
import * as semver from 'semver';
7-
import { assertion, isNullOrUndefined, mkdir } from './utils';
6+
import { assertion, isNullOrUndefined, lockfilePath, mkdir } from './utils';
87
import { spawnSync } from 'child_process';
98
import { LockFile } from './lockfile';
109
import { DryMongoBinary, BaseDryMongoBinaryOptions } from './DryMongoBinary';
@@ -31,7 +30,7 @@ export class MongoBinary {
3130
await mkdir(downloadDir);
3231

3332
/** Lockfile path */
34-
const lockfile = path.resolve(downloadDir, `${version}.lock`);
33+
const lockfile = lockfilePath(downloadDir, version);
3534
log(`download: Waiting to acquire Download lock for file "${lockfile}"`);
3635
// wait to get a lock
3736
// downloading of binaries may be quite long procedure

packages/mongodb-memory-server-core/src/util/utils.ts

+10
Original file line numberDiff line numberDiff line change
@@ -379,3 +379,13 @@ export function md5(content: BinaryLike): string {
379379
export async function md5FromFile(file: string): Promise<string> {
380380
return md5(await fspromises.readFile(file));
381381
}
382+
383+
/**
384+
* Helper function to get the lockfile for the provided `version` in `downloadDir`
385+
* @param downloadDir The Download directory of the binary
386+
* @param version The version to be downlaoded
387+
* @returns The lockfile path
388+
*/
389+
export function lockfilePath(downloadDir: string, version: string): string {
390+
return path.resolve(downloadDir, `${version}.lock`);
391+
}

0 commit comments

Comments
 (0)