AddBucketLink will add a link to another object store.
(name string, bucket ObjectStore)
| 801 | |
| 802 | // AddBucketLink will add a link to another object store. |
| 803 | func (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. |
| 844 | func (obs *obs) PutBytes(name string, data []byte, opts ...ObjectOpt) (*ObjectInfo, error) { |
nothing calls this directly
no test coverage detected