(srcDir: string, destDir: string)
| 266 | } |
| 267 | |
| 268 | const copySkillTree = (srcDir: string, destDir: string): void => { |
| 269 | for (const entry of readdirSync(srcDir, { withFileTypes: true })) { |
| 270 | const srcPath = join(srcDir, entry.name) |
| 271 | const destPath = join(destDir, entry.name) |
| 272 | const destStat = lstatIfExists(destPath) |
| 273 | if (destStat?.isSymbolicLink()) |
| 274 | throw new Error(`Refusing to write through symlink at ${destPath}`) |
| 275 | if (entry.isDirectory()) { |
| 276 | if (destStat && !destStat.isDirectory()) { |
| 277 | throw new Error( |
| 278 | `Cannot create directory at ${destPath}: path exists and is not a directory` |
| 279 | ) |
| 280 | } |
| 281 | if (!destStat) mkdirSync(destPath) |
| 282 | copySkillTree(srcPath, destPath) |
| 283 | } else if (entry.isFile()) { |
| 284 | if (destStat) { |
| 285 | if (!destStat.isFile()) { |
| 286 | throw new Error( |
| 287 | `Cannot write file at ${destPath}: path exists and is not a regular file` |
| 288 | ) |
| 289 | } |
| 290 | unlinkSync(destPath) |
| 291 | } |
| 292 | copyFileSync(srcPath, destPath, constants.COPYFILE_EXCL) |
| 293 | } |
| 294 | } |
| 295 | } |
| 296 | |
| 297 | type PreparedSkillInstall = { |
| 298 | dest: string |
no test coverage detected