AddBucketLink will add a link to another object store.
(ctx context.Context, name string, bucket ObjectStore)
| 1046 | |
| 1047 | // AddBucketLink will add a link to another object store. |
| 1048 | func (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. |
| 1089 | func (obs *obs) PutBytes(ctx context.Context, name string, data []byte) (*ObjectInfo, error) { |
nothing calls this directly
no test coverage detected