CopyObject intercept request with a SrcVersionId to read original from Version Store
(ctx context.Context, from *tree.Node, to *tree.Node, requestData *models.CopyRequestData)
| 248 | |
| 249 | // CopyObject intercept request with a SrcVersionId to read original from Version Store |
| 250 | func (v *Handler) CopyObject(ctx context.Context, from *tree.Node, to *tree.Node, requestData *models.CopyRequestData) (models.ObjectInfo, error) { |
| 251 | ctx, err := v.WrapContext(ctx) |
| 252 | if err != nil { |
| 253 | return models.ObjectInfo{}, err |
| 254 | } |
| 255 | log.Logger(ctx).Debug("CopyObject Has VersionId?", zap.Any("from", from), zap.Any("to", to), zap.Any("requestData", requestData)) |
| 256 | if len(requestData.SrcVersionId) > 0 { |
| 257 | |
| 258 | // We are trying to load a specific versionId => switch to vID store |
| 259 | if len(from.Uuid) == 0 { |
| 260 | resp, e := v.Next.ReadNode(ctx, &tree.ReadNodeRequest{Node: from}) |
| 261 | if e != nil { |
| 262 | return models.ObjectInfo{}, e |
| 263 | } |
| 264 | from = resp.Node |
| 265 | } |
| 266 | vResp, err := v.getVersionClient(ctx).HeadVersion(ctx, &tree.HeadVersionRequest{NodeUuid: from.GetUuid(), VersionId: requestData.SrcVersionId}) |
| 267 | if err != nil { |
| 268 | return models.ObjectInfo{}, err |
| 269 | } |
| 270 | if requestData.Metadata == nil { |
| 271 | requestData.Metadata = make(map[string]string, 1) |
| 272 | } |
| 273 | requestData.Metadata[common.XAmzMetaNodeUuid] = from.Uuid // Make sure to keep Uuid! |
| 274 | if h := vResp.GetVersion().GetContentHash(); h != "" { |
| 275 | // log.Logger(ctx).Info("Setting MetaNamespaceHash in CopyRequest meta") |
| 276 | requestData.Metadata[common.MetaNamespaceHash] = h |
| 277 | } |
| 278 | from = vResp.GetVersion().GetLocation() |
| 279 | // Refresh context from location |
| 280 | source, e := nodes.GetSourcesPool(ctx).GetDataSourceInfo(from.GetStringMeta(common.MetaNamespaceDatasourceName)) |
| 281 | if e != nil { |
| 282 | return models.ObjectInfo{}, e |
| 283 | } |
| 284 | srcInfo := nodes.BranchInfo{LoadedSource: source} |
| 285 | ctx = nodes.WithBranchInfo(ctx, "from", srcInfo) |
| 286 | log.Logger(ctx).Debug("CopyObject With VersionId", zap.Any("from", from), zap.Any("branchInfo", srcInfo), zap.Any("to", to)) |
| 287 | } |
| 288 | |
| 289 | return v.Next.CopyObject(ctx, from, to, requestData) |
| 290 | } |
| 291 | |
| 292 | func (v *Handler) PutObject(ctx context.Context, node *tree.Node, reader io.Reader, requestData *models.PutRequestData) (models.ObjectInfo, error) { |
| 293 | ctx, err := v.WrapContext(ctx) |
nothing calls this directly
no test coverage detected