Skip to main content

Function: ensureDir()

ensureDir(dir, maxAttempts?, mkdir?): Promise<void>

Recursive mkdir hardened against the long-standing Node concurrency bug where two processes building overlapping directory trees at the same time spuriously throw ENOENT (a peer is mid-creating a shared ancestor) or EEXIST (a peer just created this dir) — nodejs/node#27293, #31481. It is rare on local filesystems but routine on Docker overlayfs, which is where CI builds run and where this surfaced as a flaky ENOENT … mkdir '<cache>/<release>/<artifact>-<hash>' whenever concurrent builds/targets (e.g. rpm x64 + rpm armv7l, or two test workers) first populated a cold toolset cache. proper-lockfile serializes the download/extract, but the cache dir is created around the lock, so the mkdir itself must tolerate the race. Both error codes are transient: retry with a short backoff; by the next attempt the peer has finished.

Parameters

dir

string

maxAttempts?

number = 8

mkdir?

(p, opts) => Promise<unknown>

Returns

Promise<void>