Commit 3d080ff7 authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

Always return Nlink = 1 for non-directory files in

FileSystemConnector.

Test for this in ZipFs.
parent 768f8806
......@@ -242,7 +242,7 @@ func (me *testCase) testLink() {
err = os.Link(me.mountFile, me.mountSubfile)
CheckSuccess(err)
fi, err := os.Lstat(me.mountFile)
fi, err := os.Lstat(me.origFile)
if fi.Nlink != 2 {
me.tester.Errorf("Expect 2 links: %v", fi)
}
......
......@@ -69,9 +69,14 @@ func (me *FileSystemConnector) internalLookupWithNode(parent *inode, name string
}
SplitNs(mount.options.EntryTimeout, &out.EntryValid, &out.EntryValidNsec)
SplitNs(mount.options.AttrTimeout, &out.AttrValid, &out.AttrValidNsec)
if !fi.IsDirectory() {
fi.Nlink = 1
}
CopyFileInfo(fi, &out.Attr)
out.Attr.Ino = data.NodeId
mount.setOwner(&out.Attr)
return out, OK, data
}
......@@ -111,6 +116,10 @@ func (me *FileSystemConnector) GetAttr(header *InHeader, input *GetAttrIn) (out
out = &AttrOut{}
CopyFileInfo(fi, &out.Attr)
out.Attr.Ino = header.NodeId
if !fi.IsDirectory() {
out.Nlink = 1
}
mount.setOwner(&out.Attr)
SplitNs(mount.options.AttrTimeout, &out.AttrValid, &out.AttrValidNsec)
return out, OK
......
package zipfs
import (
......@@ -6,22 +7,29 @@ import (
"testing"
)
func TestZipFs(t *testing.T) {
func setupZipfs() (mountPoint string, cleanup func()) {
wd, err := os.Getwd()
CheckSuccess(err)
zfs, err := NewArchiveFileSystem(wd + "/test.zip")
if err != nil {
t.Error("NewZipArchiveFileSystem failed:", err)
}
CheckSuccess(err)
mountPoint = fuse.MakeTempDir()
mountPoint := fuse.MakeTempDir()
defer os.RemoveAll(mountPoint)
state, _, err := fuse.MountFileSystem(mountPoint, zfs, nil)
defer state.Unmount()
state.Debug = true
go state.Loop(false)
return mountPoint, func() {
state.Unmount()
os.RemoveAll(mountPoint)
}
}
func TestZipFs(t *testing.T) {
mountPoint, clean := setupZipfs()
defer clean()
d, err := os.Open(mountPoint)
CheckSuccess(err)
......@@ -58,3 +66,16 @@ func TestZipFs(t *testing.T) {
}
f.Close()
}
func TestLinkCount(t *testing.T) {
t.Log("TestLinkCount")
mp, clean := setupZipfs()
defer clean()
fi, err := os.Stat(mp + "/file.txt")
CheckSuccess(err)
if fi.Nlink != 1 {
t.Fatal("wrong link count", fi.Nlink)
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment