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

Method AddBucketLink

jetstream/object.go:1048–1086  ·  view source on GitHub ↗

AddBucketLink will add a link to another object store.

(ctx context.Context, name string, bucket ObjectStore)

Source from the content-addressed store, hash-verified

1046
1047// AddBucketLink will add a link to another object store.
1048func (ob *obs) AddBucketLink(ctx context.Context, name string, bucket ObjectStore) (*ObjectInfo, error) {
1049 if name == "" {
1050 return nil, ErrNameRequired
1051 }
1052 if bucket == nil {
1053 return nil, ErrBucketRequired
1054 }
1055 bos, ok := bucket.(*obs)
1056 if !ok {
1057 return nil, ErrBucketMalformed
1058 }
1059
1060 // If object with link's name is found, error.
1061 // If link with link's name is found, that's okay to overwrite.
1062 // If there was an error that was not ErrObjectNotFound, error.
1063 einfo, err := ob.GetInfo(ctx, name, GetObjectInfoShowDeleted())
1064 if einfo != nil {
1065 if !einfo.isLink() {
1066 return nil, ErrObjectAlreadyExists
1067 }
1068 } else if err != ErrObjectNotFound {
1069 return nil, err
1070 }
1071
1072 // create the meta for the link
1073 meta := &ObjectMeta{
1074 Name: name,
1075 Opts: &ObjectMetaOptions{Link: &ObjectLink{Bucket: bos.name}},
1076 }
1077 info := &ObjectInfo{Bucket: ob.name, NUID: nuid.Next(), ObjectMeta: *meta}
1078
1079 // put the link object
1080 err = publishMeta(ctx, info, ob.js)
1081 if err != nil {
1082 return nil, err
1083 }
1084
1085 return info, nil
1086}
1087
1088// PutBytes is convenience function to put a byte slice into this object store.
1089func (obs *obs) PutBytes(ctx context.Context, name string, data []byte) (*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