tests: catch "name too long" symlink failure on XFS

Retry with length 1000 if length 4000 fails, which
should work on all filesystems.

Failure was:

  --- FAIL: TestTooLongSymlink (0.00s)
      correctness_test.go:198: symlink xxx[...]xxxx /tmp/xfs.mnt/gocryptfs-test-parent/549823072/365091391/TooLongSymlink: file name too long

https://github.com/rfjakob/gocryptfs/issues/267
This commit is contained in:
Jakob Unterwurzacher 2018-10-10 22:38:22 +02:00
parent 5a1ebdb4f7
commit 4f2feb1be7

View File

@ -5,7 +5,6 @@ import (
"fmt"
"io/ioutil"
"os"
"runtime"
"syscall"
"testing"
@ -187,16 +186,22 @@ func TestEnoent(t *testing.T) {
// returning an I/O error to the user.
// https://github.com/rfjakob/gocryptfs/issues/167
func TestTooLongSymlink(t *testing.T) {
l := 4000
if runtime.GOOS == "darwin" {
l = 1000 // max length is much lower on darwin
}
var err error
var l int
fn := dirA + "/TooLongSymlink"
target := string(bytes.Repeat([]byte("x"), l))
err := os.Symlink(target, fn)
// Try 4000 first (works on ext4 and tmpfs), then retry with 1000 (XFS and
// Darwin have a limit of about 1024)
for _, l = range []int{4000, 1000} {
target := string(bytes.Repeat([]byte("x"), l))
err = os.Symlink(target, fn)
if err == nil {
break
}
}
if err != nil {
t.Fatal(err)
}
t.Logf("Created symlink of length %d", l)
_, err = os.Readlink(dirC + "/TooLongSymlink")
if err == nil {
return