Skip to content

Commit

Permalink
refactor(utils): add function "lockfilePath"
Browse files Browse the repository at this point in the history
and use it in "MongoBinary"
  • Loading branch information
hasezoey committed May 16, 2024
1 parent fe56c0a commit 9db479f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
5 changes: 2 additions & 3 deletions packages/mongodb-memory-server-core/src/util/MongoBinary.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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
Expand Down
10 changes: 10 additions & 0 deletions packages/mongodb-memory-server-core/src/util/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -379,3 +379,13 @@ export function md5(content: BinaryLike): string {
export async function md5FromFile(file: string): Promise<string> {
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`);
}

0 comments on commit 9db479f

Please sign in to comment.