Fixed an inode invariants bug.

geesefs-0-30-9
Aaron Jacobs 2015-03-03 14:45:39 +11:00
parent 2773133448
commit 3076da562e
1 changed files with 15 additions and 7 deletions

View File

@ -179,23 +179,31 @@ func (inode *inode) AddChild(
id fuse.InodeID, id fuse.InodeID,
name string, name string,
dt fuseutil.DirentType) { dt fuseutil.DirentType) {
var index int
// No matter where we place the entry, make sure it has the correct Offset
// field.
defer func() {
inode.entries[index].Offset = fuse.DirOffset(index + 1)
}()
// Set up the entry. // Set up the entry.
e := fuseutil.Dirent{ e := fuseutil.Dirent{
Offset: fuse.DirOffset(len(inode.entries) + 1), Inode: id,
Inode: id, Name: name,
Name: name, Type: dt,
Type: dt,
} }
// Look for a gap in which we can insert it. // Look for a gap in which we can insert it.
for i := range inode.entries { for index = range inode.entries {
if inode.entries[i].Type == fuseutil.DT_Unknown { if inode.entries[index].Type == fuseutil.DT_Unknown {
inode.entries[i] = e inode.entries[index] = e
return return
} }
} }
// Append it to the end. // Append it to the end.
index = len(inode.entries)
inode.entries = append(inode.entries, e) inode.entries = append(inode.entries, e)
} }