( taskId: string, targetPath: string, )
| 425 | * Tries to create the symlink first; if a file already exists, removes it and retries. |
| 426 | */ |
| 427 | export function initTaskOutputAsSymlink( |
| 428 | taskId: string, |
| 429 | targetPath: string, |
| 430 | ): Promise<string> { |
| 431 | return track( |
| 432 | (async () => { |
| 433 | try { |
| 434 | await ensureOutputDir() |
| 435 | const outputPath = getTaskOutputPath(taskId) |
| 436 | |
| 437 | try { |
| 438 | await symlink(targetPath, outputPath) |
| 439 | } catch { |
| 440 | await unlink(outputPath) |
| 441 | await symlink(targetPath, outputPath) |
| 442 | } |
| 443 | |
| 444 | return outputPath |
| 445 | } catch (error) { |
| 446 | logError(error) |
| 447 | return initTaskOutput(taskId) |
| 448 | } |
| 449 | })(), |
| 450 | ) |
| 451 | } |
| 452 |
no test coverage detected