| 1 | |
| 2 | |
| 3 | package reversesshfs |
| 4 | |
| 5 | import ( |
| 6 | "os" |
| 7 | "os/exec" |
| 8 | "path/filepath" |
| 9 | "strings" |
| 10 | "testing" |
| 11 | ) |
| 12 | |
| 13 | |
| 14 | |
| 15 | |
| 16 | |
| 17 | func TestSameNameCasefold(t *testing.T) { |
| 18 | if testing.Short() { |
| 19 | t.Skip("short") |
| 20 | } |
| 21 | base := os.Getenv("CASEFOLD_DIR") |
| 22 | if base == "" { |
| 23 | base = t.TempDir() |
| 24 | } |
| 25 | dir := filepath.Join(base, "cf") |
| 26 | if err := os.MkdirAll(dir, 0o755); err != nil { |
| 27 | t.Skip(err) |
| 28 | } |
| 29 | t.Cleanup(func() { os.RemoveAll(dir) }) |
| 30 | if out, err := exec.Command("chattr", "+F", dir).CombinedOutput(); err != nil { |
| 31 | t.Skipf("no casefold directory here: %v: %s", err, out) |
| 32 | } |
| 33 | if err := os.Mkdir(filepath.Join(dir, ".git"), 0o755); err != nil { |
| 34 | t.Fatal(err) |
| 35 | } |
| 36 | if _, err := os.Lstat(filepath.Join(dir, ".GIT")); err != nil { |
| 37 | t.Skip("the directory is case sensitive") |
| 38 | } |
| 39 | var found int |
| 40 | for r := rune(0x80); r <= 0x10ffff; r++ { |
| 41 | if r >= 0xd800 && r <= 0xdfff { |
| 42 | continue |
| 43 | } |
| 44 | s := string(r) |
| 45 | for _, name := range []string{".g" + s + "it", ".gi" + s + "t", ".git" + s, s + ".git", s + "git", ".g" + s + "t", ".gi" + s, "." + s + "it"} { |
| 46 | if strings.Contains(name, "/") { |
| 47 | continue |
| 48 | } |
| 49 | if _, err := os.Lstat(filepath.Join(dir, name)); err != nil { |
| 50 | continue |
| 51 | } |
| 52 | found++ |
| 53 | if !sameName(name, ".git") { |
| 54 | t.Errorf("%+q is .git on this file system, and sameName says it is not", name) |
| 55 | } |
| 56 | } |
| 57 | } |
| 58 | if found == 0 { |
| 59 | t.Error("no spelling found: the test does not reach the file system") |
| 60 | } |
| 61 | } |