github.com/quay/claircore@v1.5.28/libvuln/jsonblob/diskbuf_linux.go (about)

     1  package jsonblob
     2  
     3  import (
     4  	"context"
     5  	"errors"
     6  	"os"
     7  )
     8  
     9  // BUG(hank) On Linux, the disk buffering unconditionally uses what [os.TempDir]
    10  // reports. On most systems, this will be a tmpfs, which means the contents are
    11  // stored in RAM anyway. To mitigate this, set the "TMPDIR" environment variable
    12  // for any process that's using this package.
    13  
    14  // TODO(hank) Consolidate the spool/tempfile logic, or at least the directory
    15  // selection logic.
    16  
    17  func diskBuf(_ context.Context) (*os.File, error) {
    18  	f, err := os.CreateTemp("", "jsonblob.")
    19  	if err != nil {
    20  		return nil, err
    21  	}
    22  	if err := os.Remove(f.Name()); err != nil {
    23  		return nil, errors.Join(err, f.Close())
    24  	}
    25  	return f, nil
    26  }