| 87 | } |
| 88 | |
| 89 | func TestRootRejectsJunction(t *testing.T) { |
| 90 | rootDir := t.TempDir() |
| 91 | target := t.TempDir() |
| 92 | junction := filepath.Join(rootDir, "junction") |
| 93 | if output, err := exec.Command("cmd", "/c", "mklink", "/J", junction, target).CombinedOutput(); err != nil { |
| 94 | t.Skipf("junctions unavailable: %v: %s", err, output) |
| 95 | } |
| 96 | |
| 97 | root, err := OpenRoot(rootDir) |
| 98 | require.NoError(t, err) |
| 99 | defer root.Close() |
| 100 | |
| 101 | err = root.WriteFile(filepath.Join("junction", "file.txt"), []byte("content"), 0o644, 0o755, false) |
| 102 | require.ErrorContains(t, err, "symbolic link") |
| 103 | assert.NoFileExists(t, filepath.Join(target, "file.txt")) |
| 104 | |
| 105 | err = root.WriteFile("junction", []byte("content"), 0o644, 0o755, true) |
| 106 | require.Error(t, err) |
| 107 | info, err := os.Lstat(junction) |
| 108 | require.NoError(t, err) |
| 109 | assert.NotZero(t, info.Sys().(*syscall.Win32FileAttributeData).FileAttributes&syscall.FILE_ATTRIBUTE_REPARSE_POINT) |
| 110 | } |
| 111 | |
| 112 | func TestOpenFileRejectsWindowsTrailingSeparator(t *testing.T) { |
| 113 | tests := []struct { |