fix(ignore, fs): allow loading ignore patterns behind symlink (fixes #10785) (#10786)

The recent change to disallow following symlinks by default conflicts
with the expected behavior of .stignore. This adds a new flag which may
be passed to OpenFile to skip default symlink-forbidding open flag.

---------

Signed-off-by: Jakob Borg <jakob@kastelo.net>
This commit is contained in:
Jakob Borg
2026-07-16 09:19:13 +08:00
committed by GitHub
parent d4cffd848e
commit c1d8045d86
6 changed files with 60 additions and 5 deletions
+34
View File
@@ -1731,3 +1731,37 @@ func testEscape(t *testing.T, tests []escapeTest, noErrors bool) {
}
}
}
// TestIgnoreThroughSymlink verifies that an ignore file can be loaded when
// it is itself a symlink pointing at the real file. This exercises the
// SkipDefaultOpenFlags path, as our normal Open enforces O_NOFOLLOW. We use
// a real filesystem here because the fake one does not implement the
// O_NOFOLLOW semantics that make this distinction meaningful.
func TestIgnoreThroughSymlink(t *testing.T) {
if build.IsWindows {
t.Skip("symlinks not supported on Windows")
}
testFS := fs.NewFilesystem(fs.FilesystemTypeBasic, t.TempDir())
// The real ignore file lives under a different name, and .stignore is a
// symlink pointing at it.
if err := fs.WriteFile(testFS, "real-ignores", []byte("bfile\n"), 0o666); err != nil {
t.Fatal(err)
}
if err := testFS.CreateSymlink("real-ignores", ".stignore"); err != nil {
t.Fatal(err)
}
pats := New(testFS, WithCache(true))
if err := pats.Load(".stignore"); err != nil {
t.Fatal(err)
}
if !pats.Match("bfile").IsIgnored() {
t.Error("bfile should be ignored")
}
if pats.Match("afile").IsIgnored() {
t.Error("afile should not be ignored")
}
}