Skip to content

Commit 24b3978

Browse files
committed
fusefrontent: report correct size on hard link creation
And add a test for it. Fixes #724
1 parent b370325 commit 24b3978

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

internal/fusefrontend/node.go

+1
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,7 @@ func (n *Node) Link(ctx context.Context, target fs.InodeEmbedder, name string, o
334334
return
335335
}
336336
inode = n.newChild(ctx, st, out)
337+
n.translateSize(dirfd, cName, &out.Attr)
337338
return inode, 0
338339
}
339340

internal/fusefrontend/node_helpers.go

+1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ func (n *Node) translateSize(dirfd int, cName string, out *fuse.Attr) {
6262
rn := n.rootNode()
6363
out.Size = rn.contentEnc.CipherSizeToPlainSize(out.Size)
6464
} else if out.IsSymlink() {
65+
// read and decrypt target
6566
target, _ := n.readlink(dirfd, cName)
6667
out.Size = uint64(len(target))
6768
}

tests/matrix/matrix_test.go

+39
Original file line numberDiff line numberDiff line change
@@ -915,6 +915,45 @@ func TestSymlinkSize(t *testing.T) {
915915
}
916916
}
917917

918+
// gocryptfs 2.0+ reported the ciphertext size on hard link creation
919+
// https://github.com/rfjakob/gocryptfs/issues/724
920+
func TestLinkSize(t *testing.T) {
921+
p := filepath.Join(test_helpers.DefaultPlainDir, t.Name()) + ".regular"
922+
f, err := os.Create(p)
923+
if err != nil {
924+
t.Fatal(err)
925+
}
926+
_, err = f.WriteString("x")
927+
f.Close()
928+
if err != nil {
929+
t.Fatal(err)
930+
}
931+
doTestLinkSize(t, p)
932+
933+
p = filepath.Join(test_helpers.DefaultPlainDir, t.Name()) + ".symlink"
934+
err = syscall.Symlink("x", p)
935+
if err != nil {
936+
t.Fatal(err)
937+
}
938+
doTestLinkSize(t, p)
939+
}
940+
941+
func doTestLinkSize(t *testing.T, p string) {
942+
p2 := p + ".link"
943+
err := syscall.Link(p, p2)
944+
if err != nil {
945+
t.Fatal(err)
946+
}
947+
var st syscall.Stat_t
948+
err = syscall.Lstat(p2, &st)
949+
if err != nil {
950+
t.Fatal(filepath.Base(p2), err)
951+
}
952+
if st.Size != 1 {
953+
t.Errorf("wrong %s size: want=1 have=%d", filepath.Base(p), st.Size)
954+
}
955+
}
956+
918957
// TestPwd check that /usr/bin/pwd works inside gocryptfs.
919958
//
920959
// This was broken in gocryptfs v2.0 with -sharedstorage:

0 commit comments

Comments
 (0)