(dir: string)
| 128 | let totalSize = 0; |
| 129 | |
| 130 | async function walk(dir: string): Promise<void> { |
| 131 | if (stopped) return; |
| 132 | throwIfAborted(signal); |
| 133 | const entries = await readdir(dir, { withFileTypes: true }); |
| 134 | for (const entry of entries) { |
| 135 | if (stopped) return; |
| 136 | throwIfAborted(signal); |
| 137 | if (files.length >= limits.maxFiles) { |
| 138 | exceedsLimit = { reason: 'file-count', limit: limits.maxFiles }; |
| 139 | stopped = true; |
| 140 | return; |
| 141 | } |
| 142 | if (entry.isSymbolicLink()) continue; |
| 143 | const absolutePath = join(dir, entry.name); |
| 144 | if (entry.isDirectory()) { |
| 145 | if (isIgnoredDirName(entry.name)) continue; |
| 146 | await walk(absolutePath); |
| 147 | if (stopped) return; |
| 148 | continue; |
| 149 | } |
| 150 | if (!entry.isFile()) continue; |
| 151 | const relativePath = toPosixPath(relative(root, absolutePath)); |
| 152 | if (isSensitivePath(relativePath)) continue; |
| 153 | const file = await statFile(root, relativePath); |
| 154 | if (file) { |
| 155 | if (file.size > limits.maxFileSize) continue; |
| 156 | if (totalSize + file.size > limits.maxArchiveSize) { |
| 157 | exceedsLimit = { reason: 'total-size', limit: limits.maxArchiveSize }; |
| 158 | stopped = true; |
| 159 | return; |
| 160 | } |
| 161 | files.push(file); |
| 162 | totalSize += file.size; |
| 163 | } |
| 164 | } |
| 165 | } |
| 166 | |
| 167 | await walk(root); |
| 168 | return { files, exceedsLimit }; |
no test coverage detected