MCPcopy Create free account
hub / github.com/alibaba/open-code-review / createOutputTemp

Function createOutputTemp

cmd/opencodereview/shared.go:543–555  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

541// Unlike os.CreateTemp, the 0666 mode preserves os.Create's umask-sensitive
542// permissions for new output files.
543func 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

Callers 1

WriteMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected