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

Function createOutputTemp

cmd/opencodereview/shared.go:548–560  ·  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

546// Unlike os.CreateTemp, the 0666 mode preserves os.Create's umask-sensitive
547// permissions for new output files.
548func createOutputTemp(dir string) (*os.File, error) {
549 for range 100 {
550 path := filepath.Join(dir, outputTempPrefix+rand.Text())
551 f, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE|os.O_EXCL, 0o666)
552 if err == nil {
553 return f, nil
554 }
555 if !os.IsExist(err) {
556 return nil, err
557 }
558 }
559 return nil, fmt.Errorf("too many temporary output filename collisions in %s", dir)
560}
561
562// resolveOutputCommitPath preserves os.Create's behavior for an existing
563// 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