mirror of
https://github.com/golang/go
synced 2024-11-17 19:04:47 -07:00
ioutil.WriteFile() rather than f.Truncate()
reduce creation of the temporary file down to a single line using ioutil.WriteFile() Do not rely on truncate as to insure platforms with sendfile will predictably use it, insuring the underlying file has actual data.
This commit is contained in:
parent
13f3cda5db
commit
097364ea86
@ -1138,14 +1138,8 @@ func TestLinuxSendfile(t *testing.T) {
|
||||
|
||||
filename := fmt.Sprintf("1kb-%d", os.Getpid())
|
||||
filepath := path.Join(os.TempDir(), filename)
|
||||
f, err := os.Create(filepath)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
err = f.Truncate(1024 * 3)
|
||||
f.Sync()
|
||||
f.Close()
|
||||
if err != nil {
|
||||
|
||||
if err := ioutil.WriteFile(filepath, bytes.Repeat([]byte{'a'}, 1<<10), 0755); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer os.Remove(filepath)
|
||||
|
Loading…
Reference in New Issue
Block a user