|
1 | 1 | import type { Dirent } from 'node:fs'
|
2 | 2 | import * as fs from 'node:fs'
|
3 |
| -import { join, isAbsolute, dirname } from 'node:path' |
| 3 | +import { join } from 'node:path' |
4 | 4 | import isError from './is-error'
|
5 | 5 | import { wait } from './wait'
|
6 | 6 |
|
@@ -90,33 +90,17 @@ export async function recursiveDeleteSyncWithAsyncRetries(
|
90 | 90 | await Promise.all(
|
91 | 91 | result.map(async (part: Dirent) => {
|
92 | 92 | const absolutePath = join(dir, part.name)
|
93 |
| - |
94 |
| - // readdir does not follow symbolic links |
95 |
| - // if part is a symbolic link, follow it using stat |
96 |
| - let isDirectory = part.isDirectory() |
97 |
| - const isSymlink = part.isSymbolicLink() |
98 |
| - |
99 |
| - if (isSymlink) { |
100 |
| - const linkPath = fs.readlinkSync(absolutePath) |
101 |
| - |
102 |
| - try { |
103 |
| - const stats = fs.statSync( |
104 |
| - isAbsolute(linkPath) |
105 |
| - ? linkPath |
106 |
| - : join(dirname(absolutePath), linkPath) |
107 |
| - ) |
108 |
| - isDirectory = stats.isDirectory() |
109 |
| - } catch {} |
110 |
| - } |
111 |
| - |
112 | 93 | const pp = join(previousPath, part.name)
|
113 | 94 | const isNotExcluded = !exclude || !exclude.test(pp)
|
114 | 95 |
|
115 | 96 | if (isNotExcluded) {
|
116 |
| - if (!isSymlink && isDirectory) { |
| 97 | + // Note: readdir does not follow symbolic links, that's good: we want to |
| 98 | + // delete the links and not the destination. |
| 99 | + let isDirectory = part.isDirectory() |
| 100 | + if (isDirectory) { |
117 | 101 | await recursiveDeleteSyncWithAsyncRetries(absolutePath, exclude, pp)
|
118 | 102 | }
|
119 |
| - return unlinkPath(absolutePath, !isSymlink && isDirectory) |
| 103 | + return unlinkPath(absolutePath, isDirectory) |
120 | 104 | }
|
121 | 105 | })
|
122 | 106 | )
|
|
0 commit comments