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

Method rmSync

lib/internal/vfs/file_system.js:425–455  ·  view source on GitHub ↗

* Removes a file or directory synchronously. * @param {string} filePath The path to remove * @param {object} [options] Options * @param {boolean} [options.recursive] If true, remove directories recursively * @param {boolean} [options.force] If true, ignore ENOENT errors

(filePath, options)

Source from the content-addressed store, hash-verified

423 * @param {boolean} [options.force] If true, ignore ENOENT errors
424 */
425 rmSync(filePath, options) {
426 const recursive = options?.recursive === true;
427 const force = options?.force === true;
428
429 let stats;
430 try {
431 stats = this.lstatSync(filePath);
432 } catch (err) {
433 if (force && err?.code === 'ENOENT') return;
434 throw err;
435 }
436
437 // Symlinks should be unlinked directly, never recursed into
438 if (stats.isSymbolicLink()) {
439 this.unlinkSync(filePath);
440 return;
441 }
442
443 if (stats.isDirectory()) {
444 if (!recursive) {
445 throw createEISDIR('rm', filePath);
446 }
447 const entries = this.readdirSync(filePath);
448 for (let i = 0; i < entries.length; i++) {
449 this.rmSync(joinPath(filePath, entries[i]), options);
450 }
451 this.rmdirSync(filePath);
452 } else {
453 this.unlinkSync(filePath);
454 }
455 }
456
457 // ==================== Additional Sync Operations ====================
458

Callers 15

rmMethod · 0.95
rmSyncFunction · 0.80
removeFunction · 0.80
createVfsHandlersFunction · 0.80
test.jsFile · 0.80
rmSyncFunction · 0.80
test-fs-rm.jsFile · 0.80
cleanupFunction · 0.80

Calls 7

lstatSyncMethod · 0.95
unlinkSyncMethod · 0.95
readdirSyncMethod · 0.95
rmdirSyncMethod · 0.95
createEISDIRFunction · 0.85
isSymbolicLinkMethod · 0.45
isDirectoryMethod · 0.45

Tested by

no test coverage detected