Skip to content

Commit

Permalink
fs: return correct file size of symlink
Browse files Browse the repository at this point in the history
Signed-off-by: Kohei Tokunaga <[email protected]>
  • Loading branch information
ktock committed Mar 5, 2022
1 parent 286e23b commit deec7b2
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
3 changes: 3 additions & 0 deletions fs/layer/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,9 @@ func (sf *statFile) updateStatUnlocked() ([]byte, error) {
func entryToAttr(ino uint64, e metadata.Attr, out *fuse.Attr) fusefs.StableAttr {
out.Ino = ino
out.Size = uint64(e.Size)
if e.Mode&os.ModeSymlink != 0 {
out.Size = uint64(len(e.LinkName))
}
out.Blksize = blockSize
out.Blocks = out.Size / uint64(out.Blksize)
if out.Size%uint64(out.Blksize) > 0 {
Expand Down
25 changes: 25 additions & 0 deletions fs/layer/testutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,15 @@ func testExistence(t *testing.T, factory metadata.Store) {
hasExtraMode("test", os.ModeSticky),
},
},
{
name: "symlink_size",
in: []testutil.TarEntry{
testutil.Symlink("test", "target"),
},
want: []check{
hasSize("test", len("target")),
},
},
}

for _, tt := range tests {
Expand Down Expand Up @@ -598,6 +607,22 @@ func hasFileDigest(filename string, digest string) check {
}
}

func hasSize(name string, size int) check {
return func(t *testing.T, root *node) {
_, n, err := getDirentAndNode(t, root, name)
if err != nil {
t.Fatalf("failed to get node %q: %v", name, err)
}
var ao fuse.AttrOut
if errno := n.Operations().(fusefs.NodeGetattrer).Getattr(context.Background(), nil, &ao); errno != 0 {
t.Fatalf("failed to get attributes of node %q: %v", name, errno)
}
if ao.Attr.Size != uint64(size) {
t.Fatalf("got size = %d, want %d", ao.Attr.Size, size)
}
}
}

func hasExtraMode(name string, mode os.FileMode) check {
return func(t *testing.T, root *node) {
_, n, err := getDirentAndNode(t, root, name)
Expand Down

0 comments on commit deec7b2

Please sign in to comment.