MCPcopy
hub / github.com/git-lfs/git-lfs / TempFile

Function TempFile

tools/filetools.go:464–478  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

462// This function is designed to handle only temporary files that will be renamed
463// into place later somewhere within the Git repository.
464func 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

Callers 3

TempFileFunction · 0.92
DoTransferMethod · 0.92
downloadMethod · 0.92

Calls 4

RepositoryPermissionsMethod · 0.65
NameMethod · 0.65
CloseMethod · 0.65
RemoveMethod · 0.45

Tested by

no test coverage detected