github.com/quay/claircore@v1.5.28/libindex/tempfile_unix.go (about)

     1  //go:build unix && !linux
     2  
     3  package libindex
     4  
     5  import (
     6  	"errors"
     7  	"os"
     8  )
     9  
    10  type tempFile struct {
    11  	*os.File
    12  }
    13  
    14  func openTemp(dir string) (*tempFile, error) {
    15  	f, err := os.CreateTemp(dir, "*.fetch")
    16  	if err != nil {
    17  		return nil, err
    18  	}
    19  	return &tempFile{
    20  		File: f,
    21  	}, nil
    22  }
    23  
    24  func (t *tempFile) Reopen() (*os.File, error) {
    25  	return os.OpenFile(t.Name(), os.O_RDONLY, 0644)
    26  }
    27  
    28  func (t *tempFile) Close() error {
    29  	return errors.Join(os.Remove(t.Name()), t.File.Close())
    30  }