MCPcopy Index your code
hub / github.com/nodejs/node / mkdirSync

Method mkdirSync

lib/internal/vfs/providers/memory.js:663–715  ·  view source on GitHub ↗
(path, options)

Source from the content-addressed store, hash-verified

661 }
662
663 mkdirSync(path, options) {
664 if (this.readonly) {
665 throw createEROFS('mkdir', path);
666 }
667
668 const normalized = this.#normalizePath(path);
669 const recursive = options?.recursive === true;
670
671 // Check if already exists
672 const existing = this.#lookupEntry(normalized, true);
673 if (existing.entry) {
674 if (existing.entry.isDirectory() && recursive) {
675 // Already exists, that's ok for recursive
676 return undefined;
677 }
678 throw createEEXIST('mkdir', path);
679 }
680
681 if (recursive) {
682 // Create all parent directories
683 const segments = this.#splitPath(normalized);
684 let current = this[kRoot];
685 let currentPath = '/';
686 let firstCreated;
687
688 for (const segment of segments) {
689 currentPath = pathPosix.join(currentPath, segment);
690 let entry = current.children.get(segment);
691 if (!entry) {
692 entry = new MemoryEntry(TYPE_DIR, { mode: options?.mode });
693 entry.children = new SafeMap();
694 current.children.set(segment, entry);
695 if (firstCreated === undefined) {
696 firstCreated = currentPath;
697 }
698 } else if (!entry.isDirectory()) {
699 throw createENOTDIR('mkdir', path);
700 }
701 current = entry;
702 }
703 return firstCreated;
704 }
705
706 const parent = this.#ensureParent(normalized, false, 'mkdir');
707 const name = pathPosix.basename(normalized);
708 const entry = new MemoryEntry(TYPE_DIR, { mode: options?.mode });
709 entry.children = new SafeMap();
710 parent.children.set(name, entry);
711 const now = DateNow();
712 parent.mtime = now;
713 parent.ctime = now;
714 return undefined;
715 }
716
717 async mkdir(path, options) {
718 return this.mkdirSync(path, options);

Callers 1

mkdirMethod · 0.95

Calls 11

#normalizePathMethod · 0.95
#lookupEntryMethod · 0.95
isDirectoryMethod · 0.95
#splitPathMethod · 0.95
#ensureParentMethod · 0.95
createEROFSFunction · 0.85
createEEXISTFunction · 0.85
createENOTDIRFunction · 0.85
getMethod · 0.65
joinMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected