2013-07-05 17:41:07 +00:00
|
|
|
// +build linux darwin
|
|
|
|
|
2011-03-23 03:08:53 +00:00
|
|
|
/*
|
|
|
|
Copyright 2011 Google Inc.
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2013-07-08 01:52:14 +00:00
|
|
|
// Package fs implements a FUSE filesystem for Camlistore and is
|
|
|
|
// used by the cammount binary.
|
2011-08-07 01:46:37 +00:00
|
|
|
package fs
|
2011-03-23 03:08:53 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2011-03-24 22:33:15 +00:00
|
|
|
"io"
|
Update from r60 to [almost] Go 1.
A lot is still broken, but most stuff at least compiles now.
The directory tree has been rearranged now too. Go libraries are now
under "pkg". Fully qualified, they are e.g. "camlistore.org/pkg/jsonsign".
The go tool cannot yet fetch from arbitrary domains, but discussion is
happening now on which mechanism to use to allow that.
For now, put the camlistore root under $GOPATH/src. Typically $GOPATH
is $HOME, so Camlistore should be at $HOME/src/camlistore.org.
Then you can:
$ go build ./server/camlistored
... etc
The build.pl script is currently disabled. It'll be resurrected at
some point, but with a very different role (helping create a fake
GOPATH and running the go build command, if things are installed at
the wrong place, and/or running fileembed generators).
Many things are certainly broken.
Many things are disabled. (MySQL, all indexing, etc).
Many things need to be moved into
camlistore.org/third_party/{code.google.com,github.com} and updated
from their r60 to Go 1 versions, where applicable.
The GoMySQL stuff should be updated to use database/sql and the ziutek
library implementing database/sql/driver.
Help wanted.
Change-Id: If71217dc5c8f0e70dbe46e9504ca5131c6eeacde
2012-02-19 05:53:06 +00:00
|
|
|
"log"
|
2011-03-23 03:08:53 +00:00
|
|
|
"os"
|
2012-04-28 07:55:46 +00:00
|
|
|
"sync"
|
2012-03-19 06:14:34 +00:00
|
|
|
"syscall"
|
2012-04-30 09:43:06 +00:00
|
|
|
"time"
|
2011-03-23 03:08:53 +00:00
|
|
|
|
2013-08-04 02:54:30 +00:00
|
|
|
"camlistore.org/pkg/blob"
|
2013-02-07 05:47:01 +00:00
|
|
|
"camlistore.org/pkg/client"
|
Update from r60 to [almost] Go 1.
A lot is still broken, but most stuff at least compiles now.
The directory tree has been rearranged now too. Go libraries are now
under "pkg". Fully qualified, they are e.g. "camlistore.org/pkg/jsonsign".
The go tool cannot yet fetch from arbitrary domains, but discussion is
happening now on which mechanism to use to allow that.
For now, put the camlistore root under $GOPATH/src. Typically $GOPATH
is $HOME, so Camlistore should be at $HOME/src/camlistore.org.
Then you can:
$ go build ./server/camlistored
... etc
The build.pl script is currently disabled. It'll be resurrected at
some point, but with a very different role (helping create a fake
GOPATH and running the go build command, if things are installed at
the wrong place, and/or running fileembed generators).
Many things are certainly broken.
Many things are disabled. (MySQL, all indexing, etc).
Many things need to be moved into
camlistore.org/third_party/{code.google.com,github.com} and updated
from their r60 to Go 1 versions, where applicable.
The GoMySQL stuff should be updated to use database/sql and the ziutek
library implementing database/sql/driver.
Help wanted.
Change-Id: If71217dc5c8f0e70dbe46e9504ca5131c6eeacde
2012-02-19 05:53:06 +00:00
|
|
|
"camlistore.org/pkg/lru"
|
|
|
|
"camlistore.org/pkg/schema"
|
2012-03-19 06:14:34 +00:00
|
|
|
|
|
|
|
"camlistore.org/third_party/code.google.com/p/rsc/fuse"
|
2011-03-23 03:08:53 +00:00
|
|
|
)
|
|
|
|
|
2012-04-30 09:43:06 +00:00
|
|
|
var serverStart = time.Now()
|
|
|
|
|
2012-03-19 06:14:34 +00:00
|
|
|
var errNotDir = fuse.Errno(syscall.ENOTDIR)
|
2011-03-24 02:14:04 +00:00
|
|
|
|
2012-03-19 06:14:34 +00:00
|
|
|
type CamliFileSystem struct {
|
2013-08-04 02:54:30 +00:00
|
|
|
fetcher blob.SeekFetcher
|
2013-02-07 05:47:01 +00:00
|
|
|
client *client.Client // or nil, if not doing search queries
|
2012-04-29 04:29:51 +00:00
|
|
|
root fuse.Node
|
2011-03-23 05:11:27 +00:00
|
|
|
|
2012-04-29 00:03:07 +00:00
|
|
|
// IgnoreOwners, if true, collapses all file ownership to the
|
|
|
|
// uid/gid running the fuse filesystem, and sets all the
|
|
|
|
// permissions to 0600/0700.
|
|
|
|
IgnoreOwners bool
|
|
|
|
|
2013-01-22 18:20:34 +00:00
|
|
|
blobToSchema *lru.Cache // ~map[blobstring]*schema.Blob
|
2013-08-04 02:54:30 +00:00
|
|
|
nameToBlob *lru.Cache // ~map[string]blob.Ref
|
2011-03-26 04:36:52 +00:00
|
|
|
nameToAttr *lru.Cache // ~map[string]*fuse.Attr
|
2011-03-23 03:08:53 +00:00
|
|
|
}
|
|
|
|
|
2012-03-19 06:14:34 +00:00
|
|
|
var _ fuse.FS = (*CamliFileSystem)(nil)
|
|
|
|
|
2013-08-04 02:54:30 +00:00
|
|
|
func newCamliFileSystem(fetcher blob.SeekFetcher) *CamliFileSystem {
|
2011-03-23 05:11:27 +00:00
|
|
|
return &CamliFileSystem{
|
2011-03-26 04:21:24 +00:00
|
|
|
fetcher: fetcher,
|
|
|
|
blobToSchema: lru.New(1024), // arbitrary; TODO: tunable/smarter?
|
|
|
|
nameToBlob: lru.New(1024), // arbitrary: TODO: tunable/smarter?
|
2011-03-26 04:36:52 +00:00
|
|
|
nameToAttr: lru.New(1024), // arbitrary: TODO: tunable/smarter?
|
2011-03-23 05:11:27 +00:00
|
|
|
}
|
2011-03-23 03:08:53 +00:00
|
|
|
}
|
|
|
|
|
2012-12-26 18:16:29 +00:00
|
|
|
// NewCamliFileSystem returns a filesystem with a generic base, from which users
|
|
|
|
// can navigate by blobref, tag, date, etc.
|
2013-08-04 02:54:30 +00:00
|
|
|
func NewCamliFileSystem(client *client.Client, fetcher blob.SeekFetcher) *CamliFileSystem {
|
2013-02-07 05:47:01 +00:00
|
|
|
if client == nil || fetcher == nil {
|
|
|
|
panic("nil argument")
|
|
|
|
}
|
2012-04-29 04:29:51 +00:00
|
|
|
fs := newCamliFileSystem(fetcher)
|
|
|
|
fs.root = &root{fs: fs} // root.go
|
2013-02-07 05:47:01 +00:00
|
|
|
fs.client = client
|
2012-04-29 04:29:51 +00:00
|
|
|
return fs
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewRootedCamliFileSystem returns a CamliFileSystem with root as its
|
|
|
|
// base.
|
2013-08-04 02:54:30 +00:00
|
|
|
func NewRootedCamliFileSystem(fetcher blob.SeekFetcher, root blob.Ref) (*CamliFileSystem, error) {
|
2012-04-29 04:29:51 +00:00
|
|
|
fs := newCamliFileSystem(fetcher)
|
|
|
|
|
2013-01-22 18:20:34 +00:00
|
|
|
blob, err := fs.fetchSchemaMeta(root)
|
2012-04-29 04:29:51 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2013-01-22 18:20:34 +00:00
|
|
|
if blob.Type() != "directory" {
|
|
|
|
return nil, fmt.Errorf("Blobref must be of a directory, got a %v", blob.Type())
|
2012-10-17 22:33:37 +00:00
|
|
|
}
|
2013-01-22 18:20:34 +00:00
|
|
|
n := &node{fs: fs, blobref: root, meta: blob}
|
2012-04-29 04:29:51 +00:00
|
|
|
n.populateAttr()
|
|
|
|
fs.root = n
|
|
|
|
return fs, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// node implements fuse.Node with a read-only Camli "file" or
|
|
|
|
// "directory" blob.
|
2012-04-27 02:44:04 +00:00
|
|
|
type node struct {
|
2013-12-29 08:27:50 +00:00
|
|
|
noXattr
|
2012-04-27 02:44:04 +00:00
|
|
|
fs *CamliFileSystem
|
2013-08-04 02:54:30 +00:00
|
|
|
blobref blob.Ref
|
2012-04-28 07:55:46 +00:00
|
|
|
|
2013-02-18 19:02:26 +00:00
|
|
|
pnodeModTime time.Time // optionally set by recent.go; modtime of permanode
|
|
|
|
|
2012-04-28 11:15:45 +00:00
|
|
|
dmu sync.Mutex // guards dirents. acquire before mu.
|
|
|
|
dirents []fuse.Dirent // nil until populated once
|
|
|
|
|
2012-04-28 07:55:46 +00:00
|
|
|
mu sync.Mutex // guards rest
|
2012-04-28 01:57:24 +00:00
|
|
|
attr fuse.Attr
|
2013-01-22 18:20:34 +00:00
|
|
|
meta *schema.Blob
|
2013-08-04 02:54:30 +00:00
|
|
|
lookMap map[string]blob.Ref
|
2012-03-19 06:14:34 +00:00
|
|
|
}
|
|
|
|
|
2012-04-27 02:44:04 +00:00
|
|
|
func (n *node) Attr() (attr fuse.Attr) {
|
2012-04-28 07:55:46 +00:00
|
|
|
_, err := n.schema()
|
|
|
|
if err != nil {
|
|
|
|
// Hm, can't return it. Just log it I guess.
|
|
|
|
log.Printf("error fetching schema superset for %v: %v", n.blobref, err)
|
|
|
|
}
|
2012-04-27 08:46:31 +00:00
|
|
|
return n.attr
|
|
|
|
}
|
|
|
|
|
2013-08-04 02:54:30 +00:00
|
|
|
func (n *node) addLookupEntry(name string, ref blob.Ref) {
|
2012-04-28 07:55:46 +00:00
|
|
|
n.mu.Lock()
|
|
|
|
defer n.mu.Unlock()
|
|
|
|
if n.lookMap == nil {
|
2013-08-04 02:54:30 +00:00
|
|
|
n.lookMap = make(map[string]blob.Ref)
|
2012-04-28 07:55:46 +00:00
|
|
|
}
|
|
|
|
n.lookMap[name] = ref
|
|
|
|
}
|
|
|
|
|
2012-04-28 01:57:24 +00:00
|
|
|
func (n *node) Lookup(name string, intr fuse.Intr) (fuse.Node, fuse.Error) {
|
|
|
|
if name == ".quitquitquit" {
|
|
|
|
// TODO: only in dev mode
|
|
|
|
log.Fatalf("Shutting down due to .quitquitquit lookup.")
|
|
|
|
}
|
2012-04-28 07:55:46 +00:00
|
|
|
|
2012-04-28 11:15:45 +00:00
|
|
|
// If we haven't done Readdir yet (dirents isn't set), then force a Readdir
|
|
|
|
// call to populate lookMap.
|
|
|
|
n.dmu.Lock()
|
|
|
|
loaded := n.dirents != nil
|
|
|
|
n.dmu.Unlock()
|
|
|
|
if !loaded {
|
|
|
|
n.ReadDir(nil)
|
|
|
|
}
|
|
|
|
|
2012-04-28 07:55:46 +00:00
|
|
|
n.mu.Lock()
|
|
|
|
defer n.mu.Unlock()
|
|
|
|
ref, ok := n.lookMap[name]
|
|
|
|
if !ok {
|
|
|
|
return nil, fuse.ENOENT
|
|
|
|
}
|
|
|
|
return &node{fs: n.fs, blobref: ref}, nil
|
|
|
|
}
|
|
|
|
|
2013-01-22 18:20:34 +00:00
|
|
|
func (n *node) schema() (*schema.Blob, error) {
|
2012-04-28 07:55:46 +00:00
|
|
|
// TODO: use singleflight library here instead of a lock?
|
|
|
|
n.mu.Lock()
|
|
|
|
defer n.mu.Unlock()
|
2013-01-22 18:20:34 +00:00
|
|
|
if n.meta != nil {
|
|
|
|
return n.meta, nil
|
2012-04-28 07:55:46 +00:00
|
|
|
}
|
2013-01-22 18:20:34 +00:00
|
|
|
blob, err := n.fs.fetchSchemaMeta(n.blobref)
|
2012-04-28 07:55:46 +00:00
|
|
|
if err == nil {
|
2013-01-22 18:20:34 +00:00
|
|
|
n.meta = blob
|
2012-04-28 07:55:46 +00:00
|
|
|
n.populateAttr()
|
|
|
|
}
|
2013-01-22 18:20:34 +00:00
|
|
|
return blob, err
|
2012-04-28 01:57:24 +00:00
|
|
|
}
|
|
|
|
|
2013-12-26 21:55:27 +00:00
|
|
|
func isWriteFlags(flags uint32) bool {
|
|
|
|
return flags & uint32(os.O_WRONLY|os.O_RDWR|os.O_APPEND|os.O_CREATE) != 0
|
|
|
|
}
|
|
|
|
|
2012-04-28 11:15:45 +00:00
|
|
|
func (n *node) Open(req *fuse.OpenRequest, res *fuse.OpenResponse, intr fuse.Intr) (fuse.Handle, fuse.Error) {
|
|
|
|
log.Printf("CAMLI Open on %v: %#v", n.blobref, req)
|
2013-12-26 21:55:27 +00:00
|
|
|
if isWriteFlags(req.Flags) {
|
2013-12-22 21:06:39 +00:00
|
|
|
return nil, fuse.EPERM
|
|
|
|
}
|
2012-04-28 11:47:02 +00:00
|
|
|
ss, err := n.schema()
|
|
|
|
if err != nil {
|
|
|
|
log.Printf("open of %v: %v", n.blobref, err)
|
|
|
|
return nil, fuse.EIO
|
|
|
|
}
|
2013-01-22 18:20:34 +00:00
|
|
|
if ss.Type() == "directory" {
|
2012-04-28 11:47:02 +00:00
|
|
|
return n, nil
|
|
|
|
}
|
2012-12-26 18:02:22 +00:00
|
|
|
fr, err := ss.NewFileReader(n.fs.fetcher)
|
|
|
|
if err != nil {
|
|
|
|
// Will only happen if ss.Type != "file" or "bytes"
|
|
|
|
log.Printf("NewFileReader(%s) = %v", n.blobref, err)
|
|
|
|
return nil, fuse.EIO
|
|
|
|
}
|
|
|
|
return &nodeReader{n: n, fr: fr}, nil
|
2012-04-28 11:15:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type nodeReader struct {
|
2012-04-28 11:47:02 +00:00
|
|
|
n *node
|
2012-12-26 18:02:22 +00:00
|
|
|
fr *schema.FileReader
|
2012-04-28 11:15:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (nr *nodeReader) Read(req *fuse.ReadRequest, res *fuse.ReadResponse, intr fuse.Intr) fuse.Error {
|
2012-04-28 11:47:02 +00:00
|
|
|
log.Printf("CAMLI nodeReader READ on %v: %#v", nr.n.blobref, req)
|
2012-12-26 18:02:22 +00:00
|
|
|
if req.Offset >= nr.fr.Size() {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
size := req.Size
|
2013-02-07 05:57:07 +00:00
|
|
|
if int64(size)+req.Offset >= nr.fr.Size() {
|
2012-12-26 18:02:22 +00:00
|
|
|
size -= int((int64(size) + req.Offset) - nr.fr.Size())
|
2012-04-28 11:47:02 +00:00
|
|
|
}
|
2012-12-26 18:02:22 +00:00
|
|
|
buf := make([]byte, size)
|
|
|
|
n, err := nr.fr.ReadAt(buf, req.Offset)
|
|
|
|
if err == io.EOF {
|
|
|
|
err = nil
|
|
|
|
}
|
|
|
|
if err != nil {
|
2012-04-28 11:47:02 +00:00
|
|
|
log.Printf("camli read on %v at %d: %v", nr.n.blobref, req.Offset, err)
|
|
|
|
return fuse.EIO
|
|
|
|
}
|
|
|
|
res.Data = buf[:n]
|
|
|
|
return nil
|
2012-04-28 11:15:45 +00:00
|
|
|
}
|
|
|
|
|
2012-12-26 18:02:22 +00:00
|
|
|
func (nr *nodeReader) Release(req *fuse.ReleaseRequest, intr fuse.Intr) fuse.Error {
|
|
|
|
log.Printf("CAMLI nodeReader RELEASE on %v", nr.n.blobref)
|
|
|
|
nr.fr.Close()
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2012-04-28 01:57:24 +00:00
|
|
|
func (n *node) ReadDir(intr fuse.Intr) ([]fuse.Dirent, fuse.Error) {
|
2012-04-28 11:15:45 +00:00
|
|
|
log.Printf("CAMLI ReadDir on %v", n.blobref)
|
|
|
|
n.dmu.Lock()
|
|
|
|
defer n.dmu.Unlock()
|
|
|
|
if n.dirents != nil {
|
|
|
|
return n.dirents, nil
|
|
|
|
}
|
2012-04-28 07:55:46 +00:00
|
|
|
|
|
|
|
ss, err := n.schema()
|
|
|
|
if err != nil {
|
2013-02-18 18:17:38 +00:00
|
|
|
log.Printf("camli.ReadDir error on %v: %v", n.blobref, err)
|
2012-04-28 07:55:46 +00:00
|
|
|
return nil, fuse.EIO
|
|
|
|
}
|
2013-02-18 18:17:38 +00:00
|
|
|
dr, err := schema.NewDirReader(n.fs.fetcher, ss.BlobRef())
|
2012-04-28 07:55:46 +00:00
|
|
|
if err != nil {
|
2013-02-18 18:17:38 +00:00
|
|
|
log.Printf("camli.ReadDir error on %v: %v", n.blobref, err)
|
2012-04-28 07:55:46 +00:00
|
|
|
return nil, fuse.EIO
|
|
|
|
}
|
2013-02-18 18:17:38 +00:00
|
|
|
schemaEnts, err := dr.Readdir(-1)
|
|
|
|
if err != nil {
|
|
|
|
log.Printf("camli.ReadDir error on %v: %v", n.blobref, err)
|
2012-04-28 07:55:46 +00:00
|
|
|
return nil, fuse.EIO
|
|
|
|
}
|
2012-04-28 11:15:45 +00:00
|
|
|
n.dirents = make([]fuse.Dirent, 0)
|
2013-02-18 18:17:38 +00:00
|
|
|
for _, sent := range schemaEnts {
|
|
|
|
if name := sent.FileName(); name != "" {
|
|
|
|
n.addLookupEntry(name, sent.BlobRef())
|
|
|
|
n.dirents = append(n.dirents, fuse.Dirent{Name: name})
|
2012-04-28 07:55:46 +00:00
|
|
|
}
|
|
|
|
}
|
2012-04-28 11:15:45 +00:00
|
|
|
return n.dirents, nil
|
2012-04-28 01:57:24 +00:00
|
|
|
}
|
|
|
|
|
2012-04-28 07:55:46 +00:00
|
|
|
// populateAttr should only be called once n.ss is known to be set and
|
|
|
|
// non-nil
|
|
|
|
func (n *node) populateAttr() error {
|
2013-01-22 18:20:34 +00:00
|
|
|
meta := n.meta
|
2012-04-27 08:46:31 +00:00
|
|
|
|
2013-01-22 18:20:34 +00:00
|
|
|
n.attr.Mode = meta.FileMode()
|
2012-04-29 00:03:07 +00:00
|
|
|
|
|
|
|
if n.fs.IgnoreOwners {
|
|
|
|
n.attr.Uid = uint32(os.Getuid())
|
|
|
|
n.attr.Gid = uint32(os.Getgid())
|
|
|
|
executeBit := n.attr.Mode & 0100
|
|
|
|
n.attr.Mode = (n.attr.Mode ^ n.attr.Mode.Perm()) & 0400 & executeBit
|
|
|
|
} else {
|
2013-01-22 18:20:34 +00:00
|
|
|
n.attr.Uid = uint32(meta.MapUid())
|
|
|
|
n.attr.Gid = uint32(meta.MapGid())
|
2012-04-29 00:03:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: inode?
|
|
|
|
|
2013-02-18 19:02:26 +00:00
|
|
|
if mt := meta.ModTime(); !mt.IsZero() {
|
|
|
|
n.attr.Mtime = mt
|
|
|
|
} else {
|
|
|
|
n.attr.Mtime = n.pnodeModTime
|
|
|
|
}
|
2012-04-28 08:35:45 +00:00
|
|
|
|
2013-01-22 18:20:34 +00:00
|
|
|
switch meta.Type() {
|
2012-04-27 08:46:31 +00:00
|
|
|
case "file":
|
2013-01-22 18:20:34 +00:00
|
|
|
n.attr.Size = uint64(meta.PartsSize())
|
2012-04-28 08:35:45 +00:00
|
|
|
n.attr.Blocks = 0 // TODO: set?
|
2013-02-18 19:02:26 +00:00
|
|
|
n.attr.Mode |= 0400
|
2012-04-29 00:03:07 +00:00
|
|
|
case "directory":
|
2013-02-18 19:02:26 +00:00
|
|
|
n.attr.Mode |= 0500
|
2012-04-28 08:35:45 +00:00
|
|
|
case "symlink":
|
2013-02-18 19:02:26 +00:00
|
|
|
n.attr.Mode |= 0400
|
2012-04-27 08:46:31 +00:00
|
|
|
default:
|
2013-01-22 18:20:34 +00:00
|
|
|
log.Printf("unknown attr ss.Type %q in populateAttr", meta.Type())
|
2012-04-27 08:46:31 +00:00
|
|
|
}
|
|
|
|
return nil
|
2012-04-27 02:44:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (fs *CamliFileSystem) Root() (fuse.Node, fuse.Error) {
|
2012-04-29 04:29:51 +00:00
|
|
|
return fs.root, nil
|
2011-03-23 05:11:27 +00:00
|
|
|
}
|
|
|
|
|
2012-04-28 01:57:24 +00:00
|
|
|
func (fs *CamliFileSystem) Statfs(req *fuse.StatfsRequest, res *fuse.StatfsResponse, intr fuse.Intr) fuse.Error {
|
|
|
|
// Make some stuff up, just to see if it makes "lsof" happy.
|
|
|
|
res.Blocks = 1 << 35
|
|
|
|
res.Bfree = 1 << 34
|
2013-07-16 03:43:05 +00:00
|
|
|
res.Bavail = 1 << 34
|
2012-04-28 01:57:24 +00:00
|
|
|
res.Files = 1 << 29
|
|
|
|
res.Ffree = 1 << 28
|
|
|
|
res.Namelen = 2048
|
|
|
|
res.Bsize = 1024
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2011-03-24 05:04:50 +00:00
|
|
|
// Errors returned are:
|
2012-03-19 06:14:34 +00:00
|
|
|
// os.ErrNotExist -- blob not found
|
|
|
|
// os.ErrInvalid -- not JSON or a camli schema blob
|
2013-08-04 02:54:30 +00:00
|
|
|
func (fs *CamliFileSystem) fetchSchemaMeta(br blob.Ref) (*schema.Blob, error) {
|
2011-03-26 04:21:24 +00:00
|
|
|
blobStr := br.String()
|
2013-01-22 18:20:34 +00:00
|
|
|
if blob, ok := fs.blobToSchema.Get(blobStr); ok {
|
|
|
|
return blob.(*schema.Blob), nil
|
2011-03-26 04:21:24 +00:00
|
|
|
}
|
|
|
|
|
2011-03-23 05:11:27 +00:00
|
|
|
rsc, _, err := fs.fetcher.Fetch(br)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2011-03-23 03:35:04 +00:00
|
|
|
}
|
2011-03-23 05:11:27 +00:00
|
|
|
defer rsc.Close()
|
2013-01-22 18:20:34 +00:00
|
|
|
blob, err := schema.BlobFromReader(br, rsc)
|
2011-03-25 02:20:22 +00:00
|
|
|
if err != nil {
|
2011-03-23 05:11:27 +00:00
|
|
|
log.Printf("Error parsing %s as schema blob: %v", br, err)
|
2012-03-19 06:14:34 +00:00
|
|
|
return nil, os.ErrInvalid
|
2011-03-25 02:20:22 +00:00
|
|
|
}
|
2013-01-22 18:20:34 +00:00
|
|
|
if blob.Type() == "" {
|
2011-03-24 05:04:50 +00:00
|
|
|
log.Printf("blob %s is JSON but lacks camliType", br)
|
2012-03-19 06:14:34 +00:00
|
|
|
return nil, os.ErrInvalid
|
2011-03-24 05:04:50 +00:00
|
|
|
}
|
2013-01-22 18:20:34 +00:00
|
|
|
fs.blobToSchema.Add(blobStr, blob)
|
|
|
|
return blob, nil
|
2011-03-23 05:11:27 +00:00
|
|
|
}
|
2013-02-07 05:57:07 +00:00
|
|
|
|
2013-12-29 08:27:50 +00:00
|
|
|
type notImplementDirNode struct{ noXattr }
|
2013-02-07 05:57:07 +00:00
|
|
|
|
|
|
|
func (notImplementDirNode) Attr() fuse.Attr {
|
|
|
|
return fuse.Attr{
|
|
|
|
Mode: os.ModeDir | 0000,
|
|
|
|
Uid: uint32(os.Getuid()),
|
|
|
|
Gid: uint32(os.Getgid()),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type staticFileNode string
|
|
|
|
|
|
|
|
func (s staticFileNode) Attr() fuse.Attr {
|
|
|
|
return fuse.Attr{
|
|
|
|
Mode: 0400,
|
|
|
|
Uid: uint32(os.Getuid()),
|
|
|
|
Gid: uint32(os.Getgid()),
|
|
|
|
Size: uint64(len(s)),
|
|
|
|
Mtime: serverStart,
|
|
|
|
Ctime: serverStart,
|
|
|
|
Crtime: serverStart,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s staticFileNode) Read(req *fuse.ReadRequest, res *fuse.ReadResponse, intr fuse.Intr) fuse.Error {
|
|
|
|
if req.Offset > int64(len(s)) {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
s = s[req.Offset:]
|
|
|
|
size := req.Size
|
|
|
|
if size > len(s) {
|
|
|
|
size = len(s)
|
|
|
|
}
|
|
|
|
res.Data = make([]byte, size)
|
|
|
|
copy(res.Data, s)
|
|
|
|
return nil
|
|
|
|
}
|
2013-12-29 08:27:50 +00:00
|
|
|
|
|
|
|
func (n staticFileNode) Getxattr(*fuse.GetxattrRequest, *fuse.GetxattrResponse, fuse.Intr) fuse.Error {
|
|
|
|
return fuse.ENOATTR
|
|
|
|
}
|
|
|
|
|
|
|
|
func (n staticFileNode) Listxattr(*fuse.ListxattrRequest, *fuse.ListxattrResponse, fuse.Intr) fuse.Error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (n staticFileNode) Setxattr(*fuse.SetxattrRequest, fuse.Intr) fuse.Error {
|
|
|
|
return fuse.EPERM
|
|
|
|
}
|
|
|
|
|
|
|
|
func (n staticFileNode) Removexattr(*fuse.RemovexattrRequest, fuse.Intr) fuse.Error {
|
|
|
|
return fuse.EPERM
|
|
|
|
}
|