Skip to content

Commit

Permalink
Fix symlink
Browse files Browse the repository at this point in the history
Signed-off-by: Paulo Gomes <paulo.gomes@suse.com>
  • Loading branch information
pjbgf committed Mar 15, 2024
1 parent d0a64ab commit 9a476c0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions memfs/memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down
6 changes: 6 additions & 0 deletions memfs/memory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit 9a476c0

Please sign in to comment.