tests: convert Creat() calls to Open()

Creat() is equivalent to Open(..., O_CREAT|O_WRONLY|O_TRUNC, ...)
and MacOS does not have syscall.Creat().

https://github.com/rfjakob/gocryptfs/issues/623
This commit is contained in:
Jakob Unterwurzacher 2021-12-08 18:49:21 +01:00
parent de22cb1e5d
commit 7d60315cd5
6 changed files with 8 additions and 8 deletions

View File

@ -982,7 +982,7 @@ func TestMountCreat(t *testing.T) {
for i := 0; i < concurrency; i++ { for i := 0; i < concurrency; i++ {
go func(i int) { go func(i int) {
path := fmt.Sprintf("%s/%d", mnt, i) path := fmt.Sprintf("%s/%d", mnt, i)
fd, err := syscall.Creat(path, 0600) fd, err := syscall.Open(path, syscall.O_CREAT|syscall.O_WRONLY|syscall.O_TRUNC, 0600)
syscall.Close(fd) syscall.Close(fd)
if err != nil { if err != nil {
t.Errorf("Creat %q: %v", path, err) t.Errorf("Creat %q: %v", path, err)

View File

@ -401,7 +401,7 @@ func TestMaxlen(t *testing.T) {
func TestFsync(t *testing.T) { func TestFsync(t *testing.T) {
fileName := test_helpers.DefaultPlainDir + "/" + t.Name() + ".file" fileName := test_helpers.DefaultPlainDir + "/" + t.Name() + ".file"
fileFD, err := syscall.Creat(fileName, 0600) fileFD, err := syscall.Open(fileName, syscall.O_CREAT|syscall.O_WRONLY|syscall.O_TRUNC, 0600)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -447,7 +447,7 @@ func TestForceOwner(t *testing.T) {
// In the answer to a FUSE CREATE, gocryptfs sends file information including // In the answer to a FUSE CREATE, gocryptfs sends file information including
// the owner. This is cached by the kernel and will be used for the next // the owner. This is cached by the kernel and will be used for the next
// stat() call. // stat() call.
fd, err := syscall.Creat(foo, 0666) fd, err := syscall.Open(foo, syscall.O_CREAT|syscall.O_WRONLY|syscall.O_EXCL, 0666)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }

View File

@ -144,7 +144,7 @@ func TestInoReuse(t *testing.T) {
wg.Add(1) wg.Add(1)
go func() { go func() {
for i := 0; i < 1000; i++ { for i := 0; i < 1000; i++ {
fd, err := syscall.Creat(fn, 0600) fd, err := syscall.Open(fn, syscall.O_CREAT|syscall.O_WRONLY|syscall.O_TRUNC, 0600)
if err == syscall.EISDIR { if err == syscall.EISDIR {
continue continue
} }

View File

@ -116,7 +116,7 @@ func TestInoReuseEvil(t *testing.T) {
} }
// create a new file that will likely get the same inode number // create a new file that will likely get the same inode number
pPath2 := pPath + "2" pPath2 := pPath + "2"
fd, err := syscall.Creat(pPath2, 0600) fd, err := syscall.Open(pPath2, syscall.O_CREAT|syscall.O_WRONLY|syscall.O_TRUNC, 0600)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }

View File

@ -120,7 +120,7 @@ func writeTillFull(t *testing.T, path string) (int, syscall.Errno) {
runtime.LockOSThread() runtime.LockOSThread()
defer runtime.UnlockOSThread() defer runtime.UnlockOSThread()
fd, err := syscall.Creat(path, 0600) fd, err := syscall.Open(path, syscall.O_CREAT|syscall.O_WRONLY|syscall.O_TRUNC, 0600)
if err != nil { if err != nil {
return 0, err.(syscall.Errno) return 0, err.(syscall.Errno)
} }

View File

@ -77,7 +77,7 @@ func TestDirUnlink(t *testing.T) {
if err := unix.Rmdir(tc.mnt2 + "/foo"); err != nil { if err := unix.Rmdir(tc.mnt2 + "/foo"); err != nil {
t.Fatal(err) t.Fatal(err)
} }
if fd, err := unix.Creat(tc.mnt2+"/foo", 0600); err != nil { if fd, err := unix.Open(tc.mnt2+"/foo", unix.O_CREAT|unix.O_WRONLY|unix.O_TRUNC, 0600); err != nil {
t.Fatal(err) t.Fatal(err)
} else { } else {
unix.Close(fd) unix.Close(fd)
@ -104,7 +104,7 @@ func TestStaleHardlinks(t *testing.T) {
defer tc.cleanup() defer tc.cleanup()
link0 := tc.mnt1 + "/link0" link0 := tc.mnt1 + "/link0"
if fd, err := unix.Creat(link0, 0600); err != nil { if fd, err := unix.Open(link0, unix.O_CREAT|unix.O_WRONLY|unix.O_TRUNC, 0600); err != nil {
t.Fatal(err) t.Fatal(err)
} else { } else {
unix.Close(fd) unix.Close(fd)