createOutputTemp creates a collision-resistant file in the target directory. Unlike os.CreateTemp, the 0666 mode preserves os.Create's umask-sensitive permissions for new output files.
(dir string)
| 541 | // Unlike os.CreateTemp, the 0666 mode preserves os.Create's umask-sensitive |
| 542 | // permissions for new output files. |
| 543 | func createOutputTemp(dir string) (*os.File, error) { |
| 544 | for range 100 { |
| 545 | path := filepath.Join(dir, outputTempPrefix+rand.Text()) |
| 546 | f, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE|os.O_EXCL, 0o666) |
| 547 | if err == nil { |
| 548 | return f, nil |
| 549 | } |
| 550 | if !os.IsExist(err) { |
| 551 | return nil, err |
| 552 | } |
| 553 | } |
| 554 | return nil, fmt.Errorf("too many temporary output filename collisions in %s", dir) |
| 555 | } |
| 556 | |
| 557 | // resolveOutputCommitPath preserves os.Create's behavior for an existing |
| 558 | // symlink: write through the link to its target instead of replacing the link |