resolveOutputCommitPath preserves os.Create's behavior for an existing symlink: write through the link to its target instead of replacing the link itself during the final rename.
(path string)
| 564 | // symlink: write through the link to its target instead of replacing the link |
| 565 | // itself during the final rename. |
| 566 | func resolveOutputCommitPath(path string) (string, error) { |
| 567 | info, err := os.Lstat(path) |
| 568 | if err != nil { |
| 569 | if os.IsNotExist(err) { |
| 570 | return path, nil |
| 571 | } |
| 572 | return "", fmt.Errorf("inspect output path %s: %w", path, err) |
| 573 | } |
| 574 | if info.Mode()&os.ModeSymlink == 0 { |
| 575 | return path, nil |
| 576 | } |
| 577 | resolved, err := filepath.EvalSymlinks(path) |
| 578 | if err != nil { |
| 579 | return "", fmt.Errorf("resolve output symlink %s: %w", path, err) |
| 580 | } |
| 581 | return resolved, nil |
| 582 | } |
| 583 | |
| 584 | func cleanupOutputTemp(file *os.File, path string) error { |
| 585 | var cleanupErr error |