TempFile creates a temporary file in specified directory with proper permissions for the repository. On success, it returns an open, non-nil *os.File, and the caller is responsible for closing and/or removing it. On failure, the temporary file is automatically cleaned up and an error returned. Thi
(dir, pattern string, cfg repositoryPermissionFetcher)
| 462 | // This function is designed to handle only temporary files that will be renamed |
| 463 | // into place later somewhere within the Git repository. |
| 464 | func TempFile(dir, pattern string, cfg repositoryPermissionFetcher) (*os.File, error) { |
| 465 | tmp, err := os.CreateTemp(dir, pattern) |
| 466 | if err != nil { |
| 467 | return nil, err |
| 468 | } |
| 469 | |
| 470 | perms := cfg.RepositoryPermissions(false) |
| 471 | err = os.Chmod(tmp.Name(), perms) |
| 472 | if err != nil { |
| 473 | tmp.Close() |
| 474 | os.Remove(tmp.Name()) |
| 475 | return nil, err |
| 476 | } |
| 477 | return tmp, nil |
| 478 | } |
| 479 | |
| 480 | // ExecutablePermissions takes a set of Unix permissions (which may or may not |
| 481 | // have the executable bits set) and maps them into a set of permissions in |
no test coverage detected