2017-05-10 12:19:32 +02:00
|
|
|
// +build linux darwin freebsd
|
|
|
|
|
|
|
|
package mounttest
|
|
|
|
|
|
|
|
import (
|
2018-03-08 19:08:01 +01:00
|
|
|
"runtime"
|
2017-05-10 12:19:32 +02:00
|
|
|
"syscall"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
// TestWriteFileDoubleClose tests double close on write
|
|
|
|
func TestWriteFileDoubleClose(t *testing.T) {
|
|
|
|
run.skipIfNoFUSE(t)
|
2018-03-08 19:08:01 +01:00
|
|
|
if runtime.GOOS == "darwin" {
|
|
|
|
t.Skip("Skipping test on OSX")
|
|
|
|
}
|
2017-05-10 12:19:32 +02:00
|
|
|
|
2017-11-07 18:27:53 +01:00
|
|
|
out, err := osCreate(run.path("testdoubleclose"))
|
2017-05-10 12:19:32 +02:00
|
|
|
assert.NoError(t, err)
|
|
|
|
fd := out.Fd()
|
|
|
|
|
|
|
|
fd1, err := syscall.Dup(int(fd))
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
fd2, err := syscall.Dup(int(fd))
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
// close one of the dups - should produce no error
|
|
|
|
err = syscall.Close(fd1)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
// write to the file
|
|
|
|
buf := []byte("hello")
|
|
|
|
n, err := out.Write(buf)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, 5, n)
|
|
|
|
|
|
|
|
// close it
|
|
|
|
err = out.Close()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
// write to the other dup - should produce an error
|
2017-06-13 12:22:16 +02:00
|
|
|
_, err = syscall.Write(fd2, buf)
|
2017-05-10 12:19:32 +02:00
|
|
|
assert.Error(t, err, "input/output error")
|
|
|
|
|
2017-10-29 22:14:05 +01:00
|
|
|
// close the dup - should not produce an error
|
2017-05-10 12:19:32 +02:00
|
|
|
err = syscall.Close(fd2)
|
2017-10-29 22:14:05 +01:00
|
|
|
assert.NoError(t, err)
|
2017-05-10 12:19:32 +02:00
|
|
|
|
2017-11-18 16:50:38 +01:00
|
|
|
run.waitForWriters()
|
2017-05-10 12:19:32 +02:00
|
|
|
run.rm(t, "testdoubleclose")
|
|
|
|
}
|