2013-12-29 08:27:50 +00:00
|
|
|
// +build linux darwin
|
|
|
|
|
|
|
|
/*
|
Rename import paths from camlistore.org to perkeep.org.
Part of the project renaming, issue #981.
After this, users will need to mv their $GOPATH/src/camlistore.org to
$GOPATH/src/perkeep.org. Sorry.
This doesn't yet rename the tools like camlistored, camput, camget,
camtool, etc.
Also, this only moves the lru package to internal. More will move to
internal later.
Also, this doesn't yet remove the "/pkg/" directory. That'll likely
happen later.
This updates some docs, but not all.
devcam test now passes again, even with Go 1.10 (which requires vet
checks are clean too). So a bunch of vet tests are fixed in this CL
too, and a bunch of other broken tests are now fixed (introduced from
the past week of merging the CL backlog).
Change-Id: If580db1691b5b99f8ed6195070789b1f44877dd4
2018-01-01 22:41:41 +00:00
|
|
|
Copyright 2013 The Perkeep Authors
|
2013-12-29 08:27:50 +00:00
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package fs
|
|
|
|
|
|
|
|
import (
|
2018-01-16 23:03:16 +00:00
|
|
|
"context"
|
2013-12-29 08:27:50 +00:00
|
|
|
"encoding/base64"
|
|
|
|
"log"
|
|
|
|
"strings"
|
|
|
|
"sync"
|
|
|
|
|
Rename import paths from camlistore.org to perkeep.org.
Part of the project renaming, issue #981.
After this, users will need to mv their $GOPATH/src/camlistore.org to
$GOPATH/src/perkeep.org. Sorry.
This doesn't yet rename the tools like camlistored, camput, camget,
camtool, etc.
Also, this only moves the lru package to internal. More will move to
internal later.
Also, this doesn't yet remove the "/pkg/" directory. That'll likely
happen later.
This updates some docs, but not all.
devcam test now passes again, even with Go 1.10 (which requires vet
checks are clean too). So a bunch of vet tests are fixed in this CL
too, and a bunch of other broken tests are now fixed (introduced from
the past week of merging the CL backlog).
Change-Id: If580db1691b5b99f8ed6195070789b1f44877dd4
2018-01-01 22:41:41 +00:00
|
|
|
"perkeep.org/pkg/blob"
|
|
|
|
"perkeep.org/pkg/schema"
|
|
|
|
"perkeep.org/pkg/search"
|
2016-04-07 19:19:05 +00:00
|
|
|
|
|
|
|
"bazil.org/fuse"
|
2013-12-29 08:27:50 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// xattrPrefix is the permanode attribute prefix used for record
|
|
|
|
// extended attributes.
|
|
|
|
const xattrPrefix = "xattr:"
|
|
|
|
|
|
|
|
// xattr provides common support for extended attributes for various
|
|
|
|
// file and directory implementations (fuse.Node) within the FUSE services.
|
|
|
|
type xattr struct {
|
|
|
|
typeName string // for logging
|
|
|
|
fs *CamliFileSystem
|
|
|
|
permanode blob.Ref
|
|
|
|
|
|
|
|
// mu guards xattrs. Both mu and the xattrs map are provided by the
|
|
|
|
// fuse.Node when the struct is created.
|
|
|
|
mu *sync.Mutex
|
|
|
|
|
|
|
|
// This is a pointer to the particular fuse.Node's location of its
|
|
|
|
// xattr map so that it can be initialized commonly when the fuse.Node
|
|
|
|
// calls xattr.load(*search.DescribedPermanode)
|
|
|
|
xattrs *map[string][]byte
|
|
|
|
}
|
|
|
|
|
|
|
|
// load is invoked after the creation of a fuse.Node that may contain extended
|
|
|
|
// attributes. This creates the node's xattr map as well as fills it with any
|
|
|
|
// extended attributes found in the permanode's claims.
|
|
|
|
func (x *xattr) load(p *search.DescribedPermanode) {
|
|
|
|
x.mu.Lock()
|
|
|
|
defer x.mu.Unlock()
|
|
|
|
|
|
|
|
*x.xattrs = map[string][]byte{}
|
|
|
|
for k, v := range p.Attr {
|
|
|
|
if strings.HasPrefix(k, xattrPrefix) {
|
|
|
|
name := k[len(xattrPrefix):]
|
|
|
|
val, err := base64.StdEncoding.DecodeString(v[0])
|
|
|
|
if err != nil {
|
|
|
|
log.Printf("Base64 decoding error on attribute %v: %v", name, err)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
(*x.xattrs)[name] = val
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-16 23:03:16 +00:00
|
|
|
func (x *xattr) set(ctx context.Context, req *fuse.SetxattrRequest) error {
|
2013-12-29 08:27:50 +00:00
|
|
|
log.Printf("%s.setxattr(%q) -> %q", x.typeName, req.Name, req.Xattr)
|
|
|
|
|
|
|
|
claim := schema.NewSetAttributeClaim(x.permanode, xattrPrefix+req.Name,
|
|
|
|
base64.StdEncoding.EncodeToString(req.Xattr))
|
2018-01-16 23:03:16 +00:00
|
|
|
_, err := x.fs.client.UploadAndSignBlob(ctx, claim)
|
2013-12-29 08:27:50 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Printf("Error setting xattr: %v", err)
|
|
|
|
return fuse.EIO
|
|
|
|
}
|
|
|
|
|
2014-12-24 00:08:50 +00:00
|
|
|
val := make([]byte, len(req.Xattr))
|
|
|
|
copy(val, req.Xattr)
|
2013-12-29 08:27:50 +00:00
|
|
|
x.mu.Lock()
|
2014-12-24 00:08:50 +00:00
|
|
|
(*x.xattrs)[req.Name] = val
|
2013-12-29 08:27:50 +00:00
|
|
|
x.mu.Unlock()
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2018-01-16 23:03:16 +00:00
|
|
|
func (x *xattr) remove(ctx context.Context, req *fuse.RemovexattrRequest) error {
|
2013-12-29 08:27:50 +00:00
|
|
|
log.Printf("%s.Removexattr(%q)", x.typeName, req.Name)
|
|
|
|
|
|
|
|
claim := schema.NewDelAttributeClaim(x.permanode, xattrPrefix+req.Name, "")
|
2018-01-16 23:03:16 +00:00
|
|
|
_, err := x.fs.client.UploadAndSignBlob(ctx, claim)
|
2013-12-29 08:27:50 +00:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
log.Printf("Error removing xattr: %v", err)
|
|
|
|
return fuse.EIO
|
|
|
|
}
|
|
|
|
|
|
|
|
x.mu.Lock()
|
|
|
|
delete(*x.xattrs, req.Name)
|
|
|
|
x.mu.Unlock()
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-04-07 19:19:05 +00:00
|
|
|
func (x *xattr) get(req *fuse.GetxattrRequest, res *fuse.GetxattrResponse) error {
|
2013-12-29 08:27:50 +00:00
|
|
|
x.mu.Lock()
|
|
|
|
defer x.mu.Unlock()
|
|
|
|
|
|
|
|
val, found := (*x.xattrs)[req.Name]
|
|
|
|
|
|
|
|
if !found {
|
2016-04-07 19:19:05 +00:00
|
|
|
return fuse.ErrNoXattr
|
2013-12-29 08:27:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
res.Xattr = val
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-04-07 19:19:05 +00:00
|
|
|
func (x *xattr) list(req *fuse.ListxattrRequest, res *fuse.ListxattrResponse) error {
|
2013-12-29 08:27:50 +00:00
|
|
|
x.mu.Lock()
|
|
|
|
defer x.mu.Unlock()
|
|
|
|
|
|
|
|
for k := range *x.xattrs {
|
2014-01-14 17:04:36 +00:00
|
|
|
res.Xattr = append(res.Xattr, k...)
|
|
|
|
res.Xattr = append(res.Xattr, '\x00')
|
2013-12-29 08:27:50 +00:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|