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

Method UpdateMeta

object.go:980–1026  ·  view source on GitHub ↗

UpdateMeta will update the meta for the object.

(name string, meta *ObjectMeta)

Source from the content-addressed store, hash-verified

978
979// UpdateMeta will update the meta for the object.
980func (obs *obs) UpdateMeta(name string, meta *ObjectMeta) error {
981 if meta == nil {
982 return ErrBadObjectMeta
983 }
984
985 // Grab the current meta.
986 info, err := obs.GetInfo(name)
987 if err != nil {
988 if errors.Is(err, ErrObjectNotFound) {
989 return ErrUpdateMetaDeleted
990 }
991 return err
992 }
993
994 // If the new name is different from the old, and it exists, error
995 // If there was an error that was not ErrObjectNotFound, error.
996 if name != meta.Name {
997 existingInfo, err := obs.GetInfo(meta.Name, GetObjectInfoShowDeleted())
998 if err != nil && !errors.Is(err, ErrObjectNotFound) {
999 return err
1000 }
1001 if err == nil && !existingInfo.Deleted {
1002 return ErrObjectAlreadyExists
1003 }
1004 }
1005
1006 // Update Meta prevents update of ObjectMetaOptions (Link, ChunkSize)
1007 // These should only be updated internally when appropriate.
1008 info.Name = meta.Name
1009 info.Description = meta.Description
1010 info.Headers = meta.Headers
1011 info.Metadata = meta.Metadata
1012
1013 // Prepare the meta message
1014 if err = publishMeta(info, obs.js); err != nil {
1015 return err
1016 }
1017
1018 // did the name of this object change? We just stored the meta under the new name
1019 // so delete the meta from the old name via purge stream for subject
1020 if name != meta.Name {
1021 metaSubj := fmt.Sprintf(objMetaPreTmpl, obs.name, encodeName(name))
1022 return obs.js.purgeStream(obs.stream, &StreamPurgeRequest{Subject: metaSubj})
1023 }
1024
1025 return nil
1026}
1027
1028// Seal will seal the object store, no further modifications will be allowed.
1029func (obs *obs) Seal() error {

Callers

nothing calls this directly

Calls 6

GetInfoMethod · 0.95
purgeStreamMethod · 0.80
GetObjectInfoShowDeletedFunction · 0.70
publishMetaFunction · 0.70
encodeNameFunction · 0.70
IsMethod · 0.45

Tested by

no test coverage detected