本文整理汇总了Golang中camlistore/org/pkg/schema.NewSetAttributeClaim函数的典型用法代码示例。如果您正苦于以下问题:Golang NewSetAttributeClaim函数的具体用法?Golang NewSetAttributeClaim怎么用?Golang NewSetAttributeClaim使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewSetAttributeClaim函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: RunCommand
func (c *permanodeCmd) RunCommand(up *Uploader, args []string) error {
if len(args) > 0 {
return errors.New("Permanode command doesn't take any additional arguments")
}
var (
permaNode *client.PutResult
err error
)
permaNode, err = up.UploadNewPermanode()
if handleResult("permanode", permaNode, err) != nil {
return err
}
if c.name != "" {
put, err := up.UploadAndSignMap(schema.NewSetAttributeClaim(permaNode.BlobRef, "title", c.name))
handleResult("claim-permanode-title", put, err)
}
if c.tag != "" {
tags := strings.Split(c.tag, ",")
m := schema.NewSetAttributeClaim(permaNode.BlobRef, "tag", tags[0])
for _, tag := range tags {
m = schema.NewAddAttributeClaim(permaNode.BlobRef, "tag", tag)
put, err := up.UploadAndSignMap(m)
handleResult("claim-permanode-tag", put, err)
}
}
return nil
}
示例2: setRootNode
func (ph *PublishHandler) setRootNode(jsonSign *JSONSignHandler, pn *blobref.BlobRef) (err error) {
_, err = ph.signUpload(jsonSign, "set-attr camliRoot", schema.NewSetAttributeClaim(pn, "camliRoot", ph.RootName))
if err != nil {
return err
}
_, err = ph.signUpload(jsonSign, "set-attr title", schema.NewSetAttributeClaim(pn, "title", "Publish root node for "+ph.RootName))
return err
}
示例3: creat
func (n *mutDir) creat(name string, typ nodeType) (fuse.Node, error) {
// Create a Permanode for the file/directory.
pr, err := n.fs.client.UploadNewPermanode()
if err != nil {
return nil, err
}
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
}
// Add a child node to this node.
var child mutFileOrDir
switch typ {
case dirType:
child = &mutDir{
fs: n.fs,
permanode: pr.BlobRef,
parent: n,
name: name,
}
case fileType, symlinkType:
child = &mutFile{
fs: n.fs,
permanode: pr.BlobRef,
parent: n,
name: name,
}
default:
panic("bogus creat type")
}
n.mu.Lock()
if n.children == nil {
n.children = make(map[string]mutFileOrDir)
}
n.children[name] = child
n.mu.Unlock()
return child, nil
}
示例4: RunCommand
func (c *attrCmd) RunCommand(args []string) error {
if len(args) != 3 {
return errors.New("Attr takes 3 args: <permanode> <attr> <value>")
}
permanode, attr, value := args[0], args[1], args[2]
var err error
pn := blobref.Parse(permanode)
if pn == nil {
return fmt.Errorf("Error parsing blobref %q", permanode)
}
bb := schema.NewSetAttributeClaim(pn, attr, value)
if c.add {
if c.del {
return errors.New("Add and del options are exclusive")
}
bb = schema.NewAddAttributeClaim(pn, attr, value)
} else {
// TODO: del, which can make <value> be optional
if c.del {
return errors.New("del not yet implemented")
}
}
put, err := getUploader().UploadAndSignBlob(bb)
handleResult(bb.Type(), put, err)
return nil
}
示例5: Mkdir
func (n *rootsDir) Mkdir(req *fuse.MkdirRequest, intr fuse.Intr) (fuse.Node, fuse.Error) {
name := req.Name
// Create a Permanode for the root.
pr, err := n.fs.client.UploadNewPermanode()
if err != nil {
log.Printf("rootsDir.Create(%q): %v", name, err)
return nil, fuse.EIO
}
// Add a camliRoot attribute to the root permanode.
claim := schema.NewSetAttributeClaim(pr.BlobRef, "camliRoot", name)
_, err = n.fs.client.UploadAndSignBlob(claim)
if err != nil {
log.Printf("rootsDir.Create(%q): %v", name, err)
return nil, fuse.EIO
}
nod := &mutDir{
fs: n.fs,
permanode: pr.BlobRef,
name: name,
}
n.mu.Lock()
n.m[name] = pr.BlobRef
n.mu.Unlock()
return nod, nil
}
示例6: Rename
// &RenameRequest{Header:fuse.Header{Conn:(*fuse.Conn)(0xc210048180), ID:0x2, Node:0x8, Uid:0xf0d4, Gid:0x1388, Pid:0x5edb}, NewDir:0x8, OldName:"1", NewName:"2"}
func (n *mutDir) Rename(req *fuse.RenameRequest, newDir fuse.Node, intr fuse.Intr) fuse.Error {
n2, ok := newDir.(*mutDir)
if !ok {
log.Printf("*mutDir newDir node isn't a *mutDir; is a %T; can't handle. returning EIO.", newDir)
return fuse.EIO
}
var wg syncutil.Group
wg.Go(n.populate)
wg.Go(n2.populate)
if err := wg.Err(); err != nil {
log.Printf("*mutDir.Rename src dir populate = %v", err)
return fuse.EIO
}
n.mu.Lock()
target, ok := n.children[req.OldName]
n.mu.Unlock()
if !ok {
log.Printf("*mutDir.Rename src name %q isn't known", req.OldName)
return fuse.ENOENT
}
now := time.Now()
// Add a camliPath:name attribute to the dest permanode before unlinking it from
// the source.
claim := schema.NewSetAttributeClaim(n2.permanode, "camliPath:"+req.NewName, target.permanodeString())
claim.SetClaimDate(now)
_, err := n.fs.client.UploadAndSignBlob(claim)
if err != nil {
log.Printf("Upload rename link error: %v", err)
return fuse.EIO
}
delClaim := schema.NewDelAttributeClaim(n.permanode, "camliPath:"+req.OldName, "")
delClaim.SetClaimDate(now)
_, err = n.fs.client.UploadAndSignBlob(delClaim)
if err != nil {
log.Printf("Upload rename src unlink error: %v", err)
return fuse.EIO
}
// TODO(bradfitz): this locking would be racy, if the kernel
// doesn't do it properly. (It should) Let's just trust the
// kernel for now. Later we can verify and remove this
// comment.
n.mu.Lock()
if n.children[req.OldName] != target {
panic("Race.")
}
delete(n.children, req.OldName)
n.mu.Unlock()
n2.mu.Lock()
n2.children[req.NewName] = target
n2.mu.Unlock()
return nil
}
示例7: uploadFilePermanode
// uploadFilePermanode creates and uploads the planned permanode (with sum as a
// fixed key) associated with the file blobref fileRef.
// It also sets the optional tags for this permanode.
func (up *Uploader) uploadFilePermanode(sum string, fileRef blob.Ref, claimTime time.Time) error {
// Use a fixed time value for signing; not using modtime
// so two identical files don't have different modtimes?
// TODO(bradfitz): consider this more?
permaNodeSigTime := time.Unix(0, 0)
permaNode, err := up.UploadPlannedPermanode(sum, permaNodeSigTime)
if err != nil {
return fmt.Errorf("Error uploading planned permanode: %v", err)
}
handleResult("node-permanode", permaNode, nil)
contentAttr := schema.NewSetAttributeClaim(permaNode.BlobRef, "camliContent", fileRef.String())
contentAttr.SetClaimDate(claimTime)
signer, err := up.Signer()
if err != nil {
return err
}
signed, err := contentAttr.SignAt(signer, claimTime)
if err != nil {
return fmt.Errorf("Failed to sign content claim: %v", err)
}
put, err := up.uploadString(signed)
if err != nil {
return fmt.Errorf("Error uploading permanode's attribute: %v", err)
}
handleResult("node-permanode-contentattr", put, nil)
if tags := up.fileOpts.tags(); len(tags) > 0 {
errch := make(chan error)
for _, tag := range tags {
go func(tag string) {
m := schema.NewAddAttributeClaim(permaNode.BlobRef, "tag", tag)
m.SetClaimDate(claimTime)
signed, err := m.SignAt(signer, claimTime)
if err != nil {
errch <- fmt.Errorf("Failed to sign tag claim: %v", err)
return
}
put, err := up.uploadString(signed)
if err != nil {
errch <- fmt.Errorf("Error uploading permanode's tag attribute %v: %v", tag, err)
return
}
handleResult("node-permanode-tag", put, nil)
errch <- nil
}(tag)
}
for range tags {
if e := <-errch; e != nil && err == nil {
err = e
}
}
if err != nil {
return err
}
}
return nil
}
示例8: Rename
func (n *rootsDir) Rename(req *fuse.RenameRequest, newDir fuse.Node, intr fuse.Intr) fuse.Error {
log.Printf("rootsDir.Rename %q -> %q", req.OldName, req.NewName)
n.mu.Lock()
target, exists := n.m[req.OldName]
_, collision := n.m[req.NewName]
n.mu.Unlock()
if !exists {
log.Printf("*rootsDir.Rename src name %q isn't known", req.OldName)
return fuse.ENOENT
}
if collision {
log.Printf("*rootsDir.Rename dest %q already exists", req.NewName)
return fuse.EIO
}
// Don't allow renames if the root contains content. Rename
// is mostly implemented to make GUIs that create directories
// before asking for the directory name.
res, err := n.fs.client.Describe(&search.DescribeRequest{BlobRef: target})
if err != nil {
log.Println("rootsDir.Rename:", err)
return fuse.EIO
}
db := res.Meta[target.String()]
if db == nil {
log.Printf("Failed to pull meta for target: %v", target)
return fuse.EIO
}
for k := range db.Permanode.Attr {
const p = "camliPath:"
if strings.HasPrefix(k, p) {
log.Printf("Found file in %q: %q, disallowing rename", req.OldName, k[len(p):])
return fuse.EIO
}
}
claim := schema.NewSetAttributeClaim(target, "camliRoot", req.NewName)
_, err = n.fs.client.UploadAndSignBlob(claim)
if err != nil {
log.Printf("Upload rename link error: %v", err)
return fuse.EIO
}
// Comment transplanted from mutDir.Rename
// TODO(bradfitz): this locking would be racy, if the kernel
// doesn't do it properly. (It should) Let's just trust the
// kernel for now. Later we can verify and remove this
// comment.
n.mu.Lock()
if n.m[req.OldName] != target {
panic("Race.")
}
delete(n.m, req.OldName)
n.m[req.NewName] = target
n.mu.Unlock()
return nil
}
示例9: setContent
func (n *mutFile) setContent(br blob.Ref, size int64) error {
n.mu.Lock()
defer n.mu.Unlock()
n.content = br
n.size = size
claim := schema.NewSetAttributeClaim(n.permanode, "camliContent", br.String())
_, err := n.fs.client.UploadAndSignBlob(claim)
return err
}
示例10: Mkdir
func (n *rootsDir) Mkdir(ctx context.Context, req *fuse.MkdirRequest) (fs.Node, error) {
if n.isRO() {
return nil, fuse.EPERM
}
name := req.Name
// Create a Permanode for the root.
pr, err := n.fs.client.UploadNewPermanode()
if err != nil {
log.Printf("rootsDir.Create(%q): %v", name, err)
return nil, fuse.EIO
}
var grp syncutil.Group
// Add a camliRoot attribute to the root permanode.
grp.Go(func() (err error) {
claim := schema.NewSetAttributeClaim(pr.BlobRef, "camliRoot", name)
_, err = n.fs.client.UploadAndSignBlob(claim)
return
})
// Set the title of the root permanode to the root name.
grp.Go(func() (err error) {
claim := schema.NewSetAttributeClaim(pr.BlobRef, "title", name)
_, err = n.fs.client.UploadAndSignBlob(claim)
return
})
if err := grp.Err(); err != nil {
log.Printf("rootsDir.Create(%q): %v", name, err)
return nil, fuse.EIO
}
nod := &mutDir{
fs: n.fs,
permanode: pr.BlobRef,
name: name,
xattrs: map[string][]byte{},
}
n.mu.Lock()
n.m[name] = pr.BlobRef
n.mu.Unlock()
return nod, nil
}
示例11: RunCommand
func (c *permanodeCmd) RunCommand(args []string) error {
if len(args) > 0 {
return errors.New("Permanode command doesn't take any additional arguments")
}
var (
permaNode *client.PutResult
err error
up = getUploader()
)
if (c.key != "") != (c.sigTime != "") {
return errors.New("Both --key and --sigtime must be used to produce deterministic permanodes.")
}
if c.key == "" {
// Normal case, with a random permanode.
permaNode, err = up.UploadNewPermanode()
} else {
const format = "2006-01-02 15:04:05"
sigTime, err := time.Parse(format, c.sigTime)
if err != nil {
return fmt.Errorf("Error parsing time %q; expecting time of form %q", c.sigTime, format)
}
permaNode, err = up.UploadPlannedPermanode(c.key, sigTime)
}
if handleResult("permanode", permaNode, err) != nil {
return err
}
if c.title != "" {
put, err := up.UploadAndSignBlob(schema.NewSetAttributeClaim(permaNode.BlobRef, "title", c.title))
handleResult("claim-permanode-title", put, err)
}
if c.tag != "" {
tags := strings.Split(c.tag, ",")
m := schema.NewSetAttributeClaim(permaNode.BlobRef, "tag", tags[0])
for _, tag := range tags {
m = schema.NewAddAttributeClaim(permaNode.BlobRef, "tag", tag)
put, err := up.UploadAndSignBlob(m)
handleResult("claim-permanode-tag", put, err)
}
}
return nil
}
示例12: storePhoto
func storePhoto(p photo) (string, error) {
srcFile := localPathOf(p)
f, err := os.Open(srcFile)
if err != nil {
return "", err
}
defer f.Close()
fileRef, err := schema.WriteFileFromReader(camliClient, p.Id+"."+p.Extension, f)
res, err := camliClient.UploadNewPermanode()
if err != nil {
return "", err
}
perma := res.BlobRef
p.Description = cleanHTML(p.Description)
claims := []*schema.Builder{}
claims = append(claims, schema.NewSetAttributeClaim(perma, "camliContent", fileRef.String()))
claims = append(claims, schema.NewSetAttributeClaim(perma, "title", mkTitle(p.Description)))
claims = append(claims, schema.NewSetAttributeClaim(perma, "description", p.Description))
for _, t := range p.Tags {
claims = append(claims, schema.NewAddAttributeClaim(perma, "tag", t))
}
if p.Cat == "Public" {
claims = append(claims, schema.NewSetAttributeClaim(perma, "camliAccess", "public"))
}
grp := syncutil.Group{}
for _, claimBuilder := range claims {
claim := claimBuilder.Blob()
grp.Go(func() error {
_, err := camliClient.UploadAndSignBlob(claim)
return err
})
}
return perma.String(), grp.Err()
}
示例13: SetAttr
func (o *Object) SetAttr(key, value string) error {
_, err := o.h.upload(schema.NewSetAttributeClaim(o.pn, key, value))
if err != nil {
return err
}
o.mu.Lock()
defer o.mu.Unlock()
if o.attr == nil {
o.attr = make(map[string][]string)
}
o.attr[key] = []string{value}
return nil
}
示例14: set
func (x *xattr) set(req *fuse.SetxattrRequest) fuse.Error {
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))
_, err := x.fs.client.UploadAndSignBlob(claim)
if err != nil {
log.Printf("Error setting xattr: %v", err)
return fuse.EIO
}
x.mu.Lock()
(*x.xattrs)[req.Name] = req.Xattr
x.mu.Unlock()
return nil
}
示例15: Symlink
// &fuse.SymlinkRequest{Header:fuse.Header{Conn:(*fuse.Conn)(0xc210047180), ID:0x4, Node:0x8, Uid:0xf0d4, Gid:0x1388, Pid:0x7e88}, NewName:"some-link", Target:"../../some-target"}
func (n *mutDir) Symlink(req *fuse.SymlinkRequest, intr fuse.Intr) (fuse.Node, fuse.Error) {
node, err := n.creat(req.NewName, symlinkType)
if err != nil {
log.Printf("mutDir.Symlink(%q): %v", req.NewName, err)
return nil, fuse.EIO
}
mf := node.(*mutFile)
mf.symLink = true
mf.target = req.Target
claim := schema.NewSetAttributeClaim(mf.permanode, "camliSymlinkTarget", req.Target)
_, err = n.fs.client.UploadAndSignBlob(claim)
if err != nil {
log.Printf("mutDir.Symlink(%q) upload error: %v", req.NewName, err)
return nil, fuse.EIO
}
return node, nil
}