(path, options)
| 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); |
no test coverage detected