From 9af5a970dee4fe2898dd0a0545d51d6a5520b103 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Fri, 13 Dec 2013 13:27:48 +0400 Subject: [PATCH] Mark boring files generated by FUSE as "hidden", then hide in the UI. Makes for prettier FUSE demos w/ files showing up live in the browser with websockets. Change-Id: I41cc9ae0d33db39b4dbbf5b60714cee9a79b7248 --- pkg/fs/mut.go | 26 +++++++++++++++++--- pkg/search/query.go | 13 ++++++++++ server/camlistored/ui/blob_item_container.js | 4 ++- 3 files changed, 38 insertions(+), 5 deletions(-) diff --git a/pkg/fs/mut.go b/pkg/fs/mut.go index 098273a29..729436b1b 100644 --- a/pkg/fs/mut.go +++ b/pkg/fs/mut.go @@ -271,6 +271,12 @@ func (n *mutDir) Symlink(req *fuse.SymlinkRequest, intr fuse.Intr) (fuse.Node, f return node, nil } +func stupidMacExtendedAttributeName(name string) bool { + // TODO: if we supported extended attributes, the OS X finder wouldn't + // generate these files anyway. + return strings.HasPrefix(name, "._") || name == ".DS_Store" +} + func (n *mutDir) creat(name string, typ nodeType) (fuse.Node, error) { // Create a Permanode for the file/directory. pr, err := n.fs.client.UploadNewPermanode() @@ -278,10 +284,22 @@ func (n *mutDir) creat(name string, typ nodeType) (fuse.Node, error) { return nil, err } - // Add a camliPath:name attribute to the directory permanode. - claim := schema.NewSetAttributeClaim(n.permanode, "camliPath:"+name, pr.BlobRef.String()) - _, err = n.fs.client.UploadAndSignBlob(claim) - if err != nil { + var grp syncutil.Group + grp.Go(func() (err error) { + // Add a camliPath:name attribute to the directory permanode. + claim := schema.NewSetAttributeClaim(n.permanode, "camliPath:"+name, pr.BlobRef.String()) + _, err = n.fs.client.UploadAndSignBlob(claim) + return + }) + if stupidMacExtendedAttributeName(name) { + grp.Go(func() (err error) { + // Add a camliPath:name attribute to the directory permanode. + claim := schema.NewSetAttributeClaim(pr.BlobRef, "camliDefVis", "hide") + _, err = n.fs.client.UploadAndSignBlob(claim) + return + }) + } + if err := grp.Err(); err != nil { return nil, err } diff --git a/pkg/search/query.go b/pkg/search/query.go index fcaefc00a..5a9b695c2 100644 --- a/pkg/search/query.go +++ b/pkg/search/query.go @@ -322,6 +322,9 @@ type PermanodeConstraint struct { // This is required if any of the items below are used. Attr string `json:"attr"` + // SkipHidden skips hidden or other boring files. + SkipHidden bool `json:"skipHidden"` + // NumValue optionally tests the number of values this // permanode has for Attr. NumValue *IntConstraint `json:"numValue"` @@ -713,6 +716,16 @@ func (c *PermanodeConstraint) blobMatches(s *search, br blob.Ref, bm camtypes.Bl return false, err } } + + if c.SkipHidden && corpus != nil { + vals := corpus.AppendPermanodeAttrValuesLocked(s.ss[:0], br, "camliDefVis", time.Time{}, s.h.owner) + for _, v := range vals { + if v == "hide" { + return false, nil + } + } + } + if c.ModTime != nil { if corpus != nil { mt, ok := corpus.PermanodeModtimeLocked(br) diff --git a/server/camlistored/ui/blob_item_container.js b/server/camlistored/ui/blob_item_container.js index 7446d5568..e81ff4fa9 100644 --- a/server/camlistored/ui/blob_item_container.js +++ b/server/camlistored/ui/blob_item_container.js @@ -307,7 +307,9 @@ camlistore.BlobItemContainer.prototype.exitDocument = function() { */ camlistore.BlobItemContainer.prototype.showRecent = function() { this.search({ - camliType: 'permanode' + permanode: { + skipHidden: true + } }); };