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

Method CreateNode

common/nodes/core/handler-exec-struct.go:66–110  ·  view source on GitHub ↗
(ctx context.Context, in *tree.CreateNodeRequest, opts ...grpc.CallOption)

Source from the content-addressed store, hash-verified

64}
65
66func (f *StructStorageHandler) CreateNode(ctx context.Context, in *tree.CreateNodeRequest, opts ...grpc.CallOption) (*tree.CreateNodeResponse, error) {
67 node := in.Node
68 if !node.IsLeaf() {
69 if rr, re := f.ReadNode(ctx, &tree.ReadNodeRequest{Node: node.Clone()}); re == nil && rr != nil && rr.GetNode().IsLeaf() {
70 return nil, errors.WithMessagef(errors.NodeTypeConflict, "A file already exists with the same name, trying to insert type "+node.GetType().String())
71 }
72 dsPath := node.GetStringMeta(common.MetaNamespaceDatasourcePath)
73 newNode := &tree.Node{
74 Path: strings.TrimRight(node.Path, "/") + "/" + common.PydioSyncHiddenFile,
75 }
76 newNode.MustSetMeta(common.MetaNamespaceDatasourcePath, dsPath+"/"+common.PydioSyncHiddenFile)
77 if session := in.IndexationSession; session != "" {
78 ctx = runtimecontext.WithAdditionalMetadata(ctx, map[string]string{common.XPydioSessionUuid: session})
79 }
80 if !in.UpdateIfExists {
81 if read, er := f.GetObject(ctx, newNode, &models.GetRequestData{StartOffset: 0, Length: 36}); er == nil {
82 bytes, _ := io.ReadAll(read)
83 _ = read.Close()
84 node.Uuid = string(bytes)
85 node.MTime = time.Now().Unix()
86 node.Size = 36
87 log.Logger(ctx).Debug("[handlerExec.CreateNode] Hidden file already created", node.ZapUuid(), zap.Any("in", in))
88 return &tree.CreateNodeResponse{Node: node}, nil
89 }
90 }
91 // Create new N
92 nodeUuid := uuid.New()
93 log.Logger(ctx).Debug("[Exec] Create Folder has no Uuid")
94 if node.Uuid != "" {
95 log.Logger(ctx).Debug("Creating Folder with Uuid", node.ZapUuid())
96 nodeUuid = node.Uuid
97 }
98 _, err := f.PutObject(ctx, newNode, strings.NewReader(nodeUuid), &models.PutRequestData{Size: int64(len(nodeUuid))})
99
100 if err != nil {
101 return nil, err
102 }
103 node.Uuid = nodeUuid
104 node.MTime = time.Now().Unix()
105 node.Size = 36
106 log.Logger(ctx).Debug("[handlerExec.CreateNode] Created A Hidden .pydio for folder", node.Zap())
107 return &tree.CreateNodeResponse{Node: node}, nil
108 }
109 return f.Next.CreateNode(ctx, in, opts...)
110}
111
112func (f *StructStorageHandler) DeleteNode(ctx context.Context, in *tree.DeleteNodeRequest, opts ...grpc.CallOption) (*tree.DeleteNodeResponse, error) {
113 resp, e := f.Next.DeleteNode(ctx, in, opts...)

Callers

nothing calls this directly

Calls 15

MustSetMetaMethod · 0.95
PutObjectMethod · 0.95
LoggerFunction · 0.92
NewFunction · 0.92
IsLeafMethod · 0.65
ReadNodeMethod · 0.65
CloneMethod · 0.65
GetNodeMethod · 0.65
StringMethod · 0.65
GetTypeMethod · 0.65
GetStringMetaMethod · 0.65
GetObjectMethod · 0.65

Tested by

no test coverage detected