fs: support directories in recent files, and fix directory data race

Change-Id: I32b4989ed9b68c79168e91077d56ee65f6f62611
This commit is contained in:
Brad Fitzpatrick 2013-02-17 11:43:03 -08:00
parent bba9ba1e9a
commit a44e75435b
2 changed files with 19 additions and 4 deletions

View File

@ -264,13 +264,13 @@ func (n *node) ReadDir(intr fuse.Intr) ([]fuse.Dirent, fuse.Error) {
ssc = append(ssc, ch)
// TODO: move the cmd/camput/chanworker.go into its own package, and use it here. only
// have 10 or so of these loading at once. for now we do them all.
go func() {
go func(memberRef *blobref.BlobRef) {
mss, err := n.fs.fetchSchemaMeta(memberRef)
if err != nil {
log.Printf("error reading entry %v in readdir: %v", memberRef, err)
}
ch <- res{memberRef, mss, err}
}()
}(memberRef)
}
n.dirents = make([]fuse.Dirent, 0)

View File

@ -71,10 +71,18 @@ func (n *recentDir) ReadDir(intr fuse.Intr) ([]fuse.Dirent, fuse.Error) {
continue
}
ccMeta := res.Meta.Get(cc)
if ccMeta == nil || ccMeta.File == nil { // TODO: also allow directories
if ccMeta == nil {
continue
}
var name string
switch {
case ccMeta.File != nil:
name = ccMeta.File.FileName
case ccMeta.Dir != nil:
name = ccMeta.Dir.FileName
default:
continue
}
name := ccMeta.File.FileName
if name == "" || n.ents[name] != nil {
name = ccMeta.BlobRef.String() + path.Ext(name)
if n.ents[name] != nil {
@ -94,6 +102,13 @@ func (n *recentDir) ReadDir(intr fuse.Intr) ([]fuse.Dirent, fuse.Error) {
func (n *recentDir) Lookup(name string, intr fuse.Intr) (fuse.Node, fuse.Error) {
n.mu.Lock()
defer n.mu.Unlock()
if n.ents == nil {
// Odd case: a Lookup before a Readdir. Force a readdir to
// seed our map. Mostly hit just during development.
n.mu.Unlock() // release, since ReadDir will acquire
n.ReadDir(intr)
n.mu.Lock()
}
db := n.ents[name]
log.Printf("fs.recent: Lookup(%q) = %v", name, db)
if db == nil {