MCPcopy
hub / github.com/nats-io/nats.go / AddBucketLink

Method AddBucketLink

object.go:803–841  ·  view source on GitHub ↗

AddBucketLink will add a link to another object store.

(name string, bucket ObjectStore)

Source from the content-addressed store, hash-verified

801
802// AddBucketLink will add a link to another object store.
803func (ob *obs) AddBucketLink(name string, bucket ObjectStore) (*ObjectInfo, error) {
804 if name == "" {
805 return nil, ErrNameRequired
806 }
807 if bucket == nil {
808 return nil, ErrBucketRequired
809 }
810 bos, ok := bucket.(*obs)
811 if !ok {
812 return nil, ErrBucketMalformed
813 }
814
815 // If object with link's name is found, error.
816 // If link with link's name is found, that's okay to overwrite.
817 // If there was an error that was not ErrObjectNotFound, error.
818 einfo, err := ob.GetInfo(name, GetObjectInfoShowDeleted())
819 if einfo != nil {
820 if !einfo.isLink() {
821 return nil, ErrObjectAlreadyExists
822 }
823 } else if err != ErrObjectNotFound {
824 return nil, err
825 }
826
827 // create the meta for the link
828 meta := &ObjectMeta{
829 Name: name,
830 Opts: &ObjectMetaOptions{Link: &ObjectLink{Bucket: bos.name}},
831 }
832 info := &ObjectInfo{Bucket: ob.name, NUID: nuid.Next(), ObjectMeta: *meta}
833
834 // put the link object
835 err = publishMeta(info, ob.js)
836 if err != nil {
837 return nil, err
838 }
839
840 return info, nil
841}
842
843// PutBytes is convenience function to put a byte slice into this object store.
844func (obs *obs) PutBytes(name string, data []byte, opts ...ObjectOpt) (*ObjectInfo, error) {

Callers

nothing calls this directly

Calls 5

GetInfoMethod · 0.95
GetObjectInfoShowDeletedFunction · 0.70
publishMetaFunction · 0.70
NextMethod · 0.65
isLinkMethod · 0.45

Tested by

no test coverage detected