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
5 changes: 4 additions & 1 deletion internal/output/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ func CreateFile(path string) (*File, error) {
keep := os.FileMode(0)
if fi, err := os.Stat(path); err == nil {
if !fi.Mode().IsRegular() {
f, err := os.OpenFile(path, os.O_WRONLY|os.O_TRUNC, 0)
// No O_TRUNC: truncating a device or pipe is meaningless, and
// Windows rejects it on the NUL device with ERROR_INVALID_FUNCTION
// (#208), which broke -o NUL.
f, err := os.OpenFile(path, os.O_WRONLY, 0)
if err != nil {
return nil, err
}
Expand Down
4 changes: 0 additions & 4 deletions internal/output/lifecycle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"encoding/json"
"os"
"path/filepath"
"runtime"
"strings"
"testing"

Expand Down Expand Up @@ -97,9 +96,6 @@ func TestCreateFileMissingDirectory(t *testing.T) {
}

func TestCreateFileWritesNonRegularTargetDirectly(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("opening NUL with O_TRUNC fails on Windows")
}
fi, err := os.Stat(os.DevNull)
if err != nil || fi.Mode().IsRegular() {
t.Skipf("%s is not a device here", os.DevNull)
Expand Down
Loading