File: file.go

package info (click to toggle)
mtail 3.0.9-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 7,348 kB
  • sloc: yacc: 617; makefile: 232; sh: 104; lisp: 77; awk: 17
file content (28 lines) | stat: -rw-r--r-- 612 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package testutil

import (
	"io"
	"os"
	"testing"

	"github.com/golang/glog"
)

func WriteString(tb testing.TB, f io.StringWriter, str string) int {
	tb.Helper()
	n, err := f.WriteString(str)
	FatalIfErr(tb, err)
	glog.Infof("Wrote %d bytes", n)
	// If this is a regular file (not a pipe or other StringWriter) then ensure
	// it's flushed to disk, to guarantee the write happens-before this
	// returns.
	if v, ok := f.(*os.File); ok {
		fi, err := v.Stat()
		FatalIfErr(tb, err)
		if fi.Mode().IsRegular() {
			glog.Infof("This is a regular file, doing a sync.")
			FatalIfErr(tb, v.Sync())
		}
	}
	return n
}