* 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)
| 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 |
no test coverage detected