You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

write_unix.go 1.3 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. //go:build linux || darwin || freebsd
  2. package vfstest
  3. import (
  4. "runtime"
  5. "testing"
  6. "github.com/stretchr/testify/assert"
  7. "github.com/stretchr/testify/require"
  8. "golang.org/x/sys/unix"
  9. )
  10. // TestWriteFileDoubleClose tests double close on write
  11. func TestWriteFileDoubleClose(t *testing.T) {
  12. run.skipIfVFS(t)
  13. run.skipIfNoFUSE(t)
  14. if runtime.GOOS == "darwin" {
  15. t.Skip("Skipping test on OSX")
  16. }
  17. out, err := osCreate(run.path("testdoubleclose"))
  18. require.NoError(t, err)
  19. fd := out.Fd()
  20. fd1, err := unix.Dup(int(fd))
  21. assert.NoError(t, err)
  22. fd2, err := unix.Dup(int(fd))
  23. assert.NoError(t, err)
  24. // close one of the dups - should produce no error
  25. err = unix.Close(fd1)
  26. assert.NoError(t, err)
  27. // write to the file
  28. buf := []byte("hello")
  29. n, err := out.Write(buf)
  30. assert.NoError(t, err)
  31. assert.Equal(t, 5, n)
  32. // close it
  33. err = out.Close()
  34. assert.NoError(t, err)
  35. // write to the other dup
  36. _, err = unix.Write(fd2, buf)
  37. assert.NoError(t, err)
  38. // close the dup - should not produce an error
  39. err = unix.Close(fd2)
  40. assert.NoError(t, err)
  41. run.waitForWriters()
  42. run.rm(t, "testdoubleclose")
  43. }
  44. // writeTestDup performs the platform-specific implementation of the dup() unix
  45. func writeTestDup(oldfd uintptr) (uintptr, error) {
  46. newfd, err := unix.Dup(int(oldfd))
  47. return uintptr(newfd), err
  48. }

本项目旨在将云际存储公共基础设施化,使个人及企业可低门槛使用高效的云际存储服务(安装开箱即用云际存储客户端即可,无需关注其他组件的部署),同时支持用户灵活便捷定制云际存储的功能细节。