Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions internal/tempfile/tempfile_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (

// Create creates a temporary file that will be automatically deleted on close.
func Create(dir string) (*os.File, error) {
dir = tempDirOr(dir)

// on reasonably modern Linux (3.11 and above) O_TMPFILE is supported,
// which creates invisible, unlinked file in a given directory.
fd, err := unix.Open(dir, unix.O_RDWR|unix.O_TMPFILE|unix.O_CLOEXEC, permissions)
Expand Down
9 changes: 9 additions & 0 deletions internal/tempfile/tempfile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,12 @@ func TestTempFile(t *testing.T) {
require.NoError(t, err)
require.Empty(t, files)
}

func TestCreateSucceedsWhenDirIsNotSpecified(t *testing.T) {
f, err := tempfile.Create("")

require.NoError(t, err)

err = f.Close()
require.NoError(t, err)
}
Loading