MCPcopy Create free account
hub / github.com/pydio/cells / CopyObject

Method CopyObject

common/nodes/core/handler-exec-flat.go:107–164  ·  view source on GitHub ↗
(ctx context.Context, from *tree.Node, to *tree.Node, requestData *models.CopyRequestData)

Source from the content-addressed store, hash-verified

105}
106
107func (f *FlatStorageHandler) CopyObject(ctx context.Context, from *tree.Node, to *tree.Node, requestData *models.CopyRequestData) (models.ObjectInfo, error) {
108
109 var revertNode *tree.Node
110 if requestData.Metadata == nil {
111 requestData.Metadata = map[string]string{}
112 }
113 if nodes.IsFlatStorage(ctx, "to") {
114 if len(requestData.SrcVersionId) > 0 {
115 if e := f.resolveUUID(ctx, to); e != nil {
116 return models.ObjectInfo{}, e
117 }
118 } else {
119 // Insert in tree as temporary
120 temporary := to.Clone()
121 if dir, o := requestData.Metadata[common.XAmzMetaDirective]; o && dir == "COPY" { // MOVE CASE = Copy original metadata
122 temporary.Uuid = from.Uuid
123 } else if temporary.Uuid == "" || temporary.Uuid == from.Uuid {
124 temporary.Uuid = uuid.New()
125 // Copy - Uuid maybe specified by a previous handler
126 if metaUuid, ok := requestData.Metadata[common.XAmzMetaNodeUuid]; ok && metaUuid != "" {
127 temporary.Uuid = metaUuid
128 }
129 }
130 temporary.Type = tree.NodeType_LEAF
131 temporary.Etag = common.NodeFlagEtagTemporary
132 if ctype := from.GetStringMeta(common.MetaNamespaceMime); ctype != "" {
133 temporary.MustSetMeta(common.MetaNamespaceMime, ctype)
134 }
135 if _, er := nodes.GetSourcesPool(ctx).GetTreeClientWrite().CreateNode(ctx, &tree.CreateNodeRequest{Node: temporary}); er != nil {
136 return models.ObjectInfo{}, er
137 }
138 // Attach Uuid to target node
139 to.Uuid = temporary.Uuid
140 revertNode = temporary
141 }
142 }
143 objectInfo, e := f.Next.CopyObject(ctx, from, to, requestData)
144 if e == nil && nodes.IsFlatStorage(ctx, "to") {
145 // Create an "in" context with resolver
146 destInfo, _ := nodes.GetBranchInfo(ctx, "to")
147 tgtCtx := nodes.WithBranchInfo(ctx, "in", destInfo)
148 if _, ok := requestData.Metadata[common.XPydioMoveUuid]; ok {
149 tgtCtx = propagator.WithAdditionalMetadata(tgtCtx, requestData.Metadata)
150 }
151 requestData.Metadata[common.MetaNamespaceMime] = from.GetStringMeta(common.MetaNamespaceMime)
152 // Now store in index
153 if er := f.postCreate(tgtCtx, to, requestData.Metadata, &objectInfo); er != nil {
154 return objectInfo, er
155 }
156 } else if e != nil && revertNode != nil {
157 if _, de := nodes.GetSourcesPool(ctx).GetTreeClientWrite().DeleteNode(ctx, &tree.DeleteNodeRequest{Node: revertNode}); de != nil {
158 log.Logger(ctx).Error("Error while copying object and error while reverting index node", zap.Error(de), revertNode.ZapPath())
159 } else {
160 log.Logger(ctx).Warn("Error while copying object, reverted index node", revertNode.ZapPath())
161 }
162 }
163 return objectInfo, e
164}

Callers

nothing calls this directly

Calls 15

resolveUUIDMethod · 0.95
postCreateMethod · 0.95
ZapPathMethod · 0.95
IsFlatStorageFunction · 0.92
NewFunction · 0.92
GetSourcesPoolFunction · 0.92
GetBranchInfoFunction · 0.92
WithBranchInfoFunction · 0.92
WithAdditionalMetadataFunction · 0.92
LoggerFunction · 0.92
MustSetMetaMethod · 0.80
CloneMethod · 0.65

Tested by

no test coverage detected