MCPcopy Create free account
hub / github.com/github/gh-aw / writeDownloadedIncludeToTempFile

Function writeDownloadedIncludeToTempFile

pkg/parser/remote_fetch.go:416–449  ·  view source on GitHub ↗
(content []byte)

Source from the content-addressed store, hash-verified

414}
415
416func writeDownloadedIncludeToTempFile(content []byte) (string, error) {
417 tempFile, err := os.CreateTemp("", "gh-aw-include-*.md")
418 if err != nil {
419 return "", fmt.Errorf("failed to create temp file: %w", err)
420 }
421 cleanupOnError := true
422 fileClosed := false
423 defer func() {
424 if cleanupOnError {
425 if !fileClosed {
426 if closeErr := tempFile.Close(); closeErr != nil {
427 remoteLog.Printf("Warning: failed to close temp file during deferred cleanup: %v", closeErr)
428 }
429 }
430 if rmErr := os.Remove(tempFile.Name()); rmErr != nil && !os.IsNotExist(rmErr) {
431 remoteLog.Printf("Warning: failed to remove temp file %s: %v", tempFile.Name(), rmErr)
432 }
433 }
434 }()
435 if _, err := tempFile.Write(content); err != nil {
436 if closeErr := tempFile.Close(); closeErr != nil {
437 remoteLog.Printf("Warning: failed to close temp file during cleanup: %v", closeErr)
438 }
439 fileClosed = true
440 return "", fmt.Errorf("failed to write temp file: %w", err)
441 }
442 if err := tempFile.Close(); err != nil {
443 fileClosed = true
444 return "", fmt.Errorf("failed to close temp file: %w", err)
445 }
446 cleanupOnError = false
447 fileClosed = true
448 return tempFile.Name(), nil
449}
450
451// resolveRefToSHAViaGit resolves a git ref to SHA using git ls-remote
452// This is a fallback for when GitHub API authentication fails

Callers 1

Calls 4

WriteMethod · 0.80
CloseMethod · 0.65
ErrorfMethod · 0.45
PrintfMethod · 0.45

Tested by

no test coverage detected