From 9a476c046990034bf44699a412a73dd730707a61 Mon Sep 17 00:00:00 2001 From: Paulo Gomes Date: Fri, 15 Mar 2024 20:05:35 +0000 Subject: [PATCH] Fix symlink Signed-off-by: Paulo Gomes --- memfs/memory.go | 3 +++ memfs/memory_test.go | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/memfs/memory.go b/memfs/memory.go index 2641238..c008702 100644 --- a/memfs/memory.go +++ b/memfs/memory.go @@ -59,6 +59,9 @@ func (fs *Memory) OpenFile(filename string, flag int, perm os.FileMode) (billy.F } if target, isLink := fs.resolveLink(filename, f); isLink { + if target == filename { + return nil, os.ErrNotExist + } return fs.OpenFile(target, flag, perm) } } diff --git a/memfs/memory_test.go b/memfs/memory_test.go index 030c58a..043a9fb 100644 --- a/memfs/memory_test.go +++ b/memfs/memory_test.go @@ -121,3 +121,9 @@ func (s *MemorySuite) TestTruncateAppend(c *C) { c.Assert(err, IsNil) c.Assert(string(data), Equals, "replace") } + +func (s *MemorySuite) TestSymlink(c *C) { + s.FS.Symlink("test", "test") + _, err := s.FS.Open("test") + c.Assert(err, NotNil) +}