AddLink will add a link to another object if it's not deleted and not another link name is the name of this link object obj is what is being linked too
(name string, obj *ObjectInfo)
| 756 | // name is the name of this link object |
| 757 | // obj is what is being linked too |
| 758 | func (obs *obs) AddLink(name string, obj *ObjectInfo) (*ObjectInfo, error) { |
| 759 | if name == "" { |
| 760 | return nil, ErrNameRequired |
| 761 | } |
| 762 | |
| 763 | // TODO Handle stale info |
| 764 | |
| 765 | if obj == nil || obj.Name == "" { |
| 766 | return nil, ErrObjectRequired |
| 767 | } |
| 768 | if obj.Deleted { |
| 769 | return nil, ErrNoLinkToDeleted |
| 770 | } |
| 771 | if obj.isLink() { |
| 772 | return nil, ErrNoLinkToLink |
| 773 | } |
| 774 | |
| 775 | // If object with link's name is found, error. |
| 776 | // If link with link's name is found, that's okay to overwrite. |
| 777 | // If there was an error that was not ErrObjectNotFound, error. |
| 778 | einfo, err := obs.GetInfo(name, GetObjectInfoShowDeleted()) |
| 779 | if einfo != nil { |
| 780 | if !einfo.isLink() { |
| 781 | return nil, ErrObjectAlreadyExists |
| 782 | } |
| 783 | } else if err != ErrObjectNotFound { |
| 784 | return nil, err |
| 785 | } |
| 786 | |
| 787 | // create the meta for the link |
| 788 | meta := &ObjectMeta{ |
| 789 | Name: name, |
| 790 | Opts: &ObjectMetaOptions{Link: &ObjectLink{Bucket: obj.Bucket, Name: obj.Name}}, |
| 791 | } |
| 792 | info := &ObjectInfo{Bucket: obs.name, NUID: nuid.Next(), ModTime: time.Now().UTC(), ObjectMeta: *meta} |
| 793 | |
| 794 | // put the link object |
| 795 | if err = publishMeta(info, obs.js); err != nil { |
| 796 | return nil, err |
| 797 | } |
| 798 | |
| 799 | return info, nil |
| 800 | } |
| 801 | |
| 802 | // AddBucketLink will add a link to another object store. |
| 803 | func (ob *obs) AddBucketLink(name string, bucket ObjectStore) (*ObjectInfo, error) { |
nothing calls this directly
no test coverage detected