MCPcopy Create free account
hub / github.com/Noumena-Network/code / writeIfMissing

Function writeIfMissing

src/utils/localInstaller.ts:54–66  ·  view source on GitHub ↗

* Write `content` to `path` only if the file does not already exist. * Uses O_EXCL ('wx') for atomic create-if-missing.

(
  path: string,
  content: string,
  mode?: number,
)

Source from the content-addressed store, hash-verified

52 * Uses O_EXCL ('wx') for atomic create-if-missing.
53 */
54async function writeIfMissing(
55 path: string,
56 content: string,
57 mode?: number,
58): Promise<boolean> {
59 try {
60 await writeFile(path, content, { encoding: 'utf8', flag: 'wx', mode })
61 return true
62 } catch (e) {
63 if (getErrnoCode(e) === 'EEXIST') return false
64 throw e
65 }
66}
67
68/**
69 * Ensure the local package environment is set up

Callers 1

Calls 1

getErrnoCodeFunction · 0.85

Tested by

no test coverage detected