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

Method linkSync

lib/internal/vfs/providers/memory.js:823–851  ·  view source on GitHub ↗
(existingPath, newPath)

Source from the content-addressed store, hash-verified

821 }
822
823 linkSync(existingPath, newPath) {
824 if (this.readonly) {
825 throw createEROFS('link', newPath);
826 }
827
828 const normalizedExisting = this.#normalizePath(existingPath);
829 const normalizedNew = this.#normalizePath(newPath);
830
831 const entry = this.#getEntry(normalizedExisting, 'link', true);
832 if (!entry.isFile()) {
833 // Hard links to directories are not supported
834 throw createEINVAL('link', existingPath);
835 }
836
837 // Check if new path already exists
838 const existing = this.#lookupEntry(normalizedNew, false);
839 if (existing.entry) {
840 throw createEEXIST('link', newPath);
841 }
842
843 const parent = this.#ensureParent(normalizedNew, false, 'link');
844 const name = pathPosix.basename(normalizedNew);
845 // Hard link: same entry object referenced by both names
846 parent.children.set(name, entry);
847 entry.nlink++;
848 const now = DateNow();
849 parent.mtime = now;
850 parent.ctime = now;
851 }
852
853 async link(existingPath, newPath) {
854 this.linkSync(existingPath, newPath);

Callers 1

linkMethod · 0.95

Calls 9

#normalizePathMethod · 0.95
#getEntryMethod · 0.95
#lookupEntryMethod · 0.95
#ensureParentMethod · 0.95
createEROFSFunction · 0.85
createEINVALFunction · 0.85
createEEXISTFunction · 0.85
isFileMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected