add a hard link marker to 16byte + maker, for future extensions

This commit is contained in:
Chris Lu 2020-09-27 22:38:30 -07:00
parent c49e2bb9a3
commit 474e2b6ac3

View file

@ -18,6 +18,10 @@ var _ = fs.NodeLinker(&Dir{})
var _ = fs.NodeSymlinker(&Dir{}) var _ = fs.NodeSymlinker(&Dir{})
var _ = fs.NodeReadlinker(&File{}) var _ = fs.NodeReadlinker(&File{})
const (
HARD_LINK_MARKER = '\x01'
)
func (dir *Dir) Link(ctx context.Context, req *fuse.LinkRequest, old fs.Node) (fs.Node, error) { func (dir *Dir) Link(ctx context.Context, req *fuse.LinkRequest, old fs.Node) (fs.Node, error) {
oldFile, ok := old.(*File) oldFile, ok := old.(*File)
@ -33,7 +37,7 @@ func (dir *Dir) Link(ctx context.Context, req *fuse.LinkRequest, old fs.Node) (f
// update old file to hardlink mode // update old file to hardlink mode
if len(oldFile.entry.HardLinkId) == 0 { if len(oldFile.entry.HardLinkId) == 0 {
oldFile.entry.HardLinkId = util.RandomBytes(16) oldFile.entry.HardLinkId = append(util.RandomBytes(16), HARD_LINK_MARKER)
oldFile.entry.HardLinkCounter = 1 oldFile.entry.HardLinkCounter = 1
} }
oldFile.entry.HardLinkCounter++ oldFile.entry.HardLinkCounter++