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

Function copyDir

lib/internal/fs/cp/cp-sync.js:140–186  ·  view source on GitHub ↗
(src, dest, opts, mkDir, srcMode)

Source from the content-addressed store, hash-verified

138}
139
140function copyDir(src, dest, opts, mkDir, srcMode) {
141 if (!opts.filter) {
142 // The caller didn't provide a js filter function, in this case
143 // we can run the whole function faster in C++
144 // TODO(dario-piotrowicz): look into making cpSyncCopyDir also accept the potential filter function
145 return fsBinding.cpSyncCopyDir(src, dest,
146 opts.force,
147 opts.dereference,
148 opts.errorOnExist,
149 opts.verbatimSymlinks,
150 opts.preserveTimestamps);
151 }
152
153 if (mkDir) {
154 mkdirSync(dest);
155 }
156
157 const dir = opendirSync(src);
158
159 try {
160 let dirent;
161
162 while ((dirent = dir.readSync()) !== null) {
163 const { name } = dirent;
164 const srcItem = join(src, name);
165 const destItem = join(dest, name);
166 let shouldCopy = true;
167
168 if (opts.filter) {
169 shouldCopy = opts.filter(srcItem, destItem);
170 if (isPromise(shouldCopy)) {
171 throw new ERR_INVALID_RETURN_VALUE('boolean', 'filter', shouldCopy);
172 }
173 }
174
175 if (shouldCopy) {
176 getStats(srcItem, destItem, opts);
177 }
178 }
179 } finally {
180 dir.closeSync();
181
182 if (srcMode !== undefined) {
183 setDestMode(dest, srcMode);
184 }
185 }
186}
187
188// TODO(@anonrig): Move this function to C++.
189function onLink(destStat, src, dest, verbatimSymlinks) {

Callers 1

onDirFunction · 0.70

Calls 8

opendirSyncFunction · 0.85
getStatsFunction · 0.70
setDestModeFunction · 0.70
filterMethod · 0.65
mkdirSyncFunction · 0.50
joinFunction · 0.50
readSyncMethod · 0.45
closeSyncMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…