MCPcopy
hub / github.com/OpenListTeam/OpenList / RunWithNextTaskCallback

Method RunWithNextTaskCallback

internal/fs/copy_move.go:179–264  ·  view source on GitHub ↗
(f func(nextTask *FileTransferTask) error)

Source from the content-addressed store, hash-verified

177}
178
179func (t *FileTransferTask) RunWithNextTaskCallback(f func(nextTask *FileTransferTask) error) error {
180 t.Status = "getting src object"
181 srcObj, err := op.Get(t.Ctx(), t.SrcStorage, t.SrcActualPath)
182 if err != nil {
183 return errors.WithMessagef(err, "failed get src [%s] file", t.SrcActualPath)
184 }
185
186 if srcObj.IsDir() {
187 t.Status = "src object is dir, listing objs"
188 objs, err := op.List(t.Ctx(), t.SrcStorage, t.SrcActualPath, model.ListArgs{})
189 if err != nil {
190 return errors.WithMessagef(err, "failed list src [%s] objs", t.SrcActualPath)
191 }
192 dstActualPath := stdpath.Join(t.DstActualPath, srcObj.GetName())
193 task_group.TransferCoordinator.AppendPayload(t.groupID, task_group.DstPathToHook(dstActualPath))
194
195 existedObjs := make(map[string]bool)
196 if t.TaskType == merge {
197 dstObjs, err := op.List(t.Ctx(), t.DstStorage, dstActualPath, model.ListArgs{})
198 if err != nil && !errors.Is(err, errs.ObjectNotFound) {
199 // 目标文件夹不存在的情况不是错误,会在之后新建文件夹
200 // 这种情况显然不需要统计existedObjs,dstObjs保持为nil,下面这个for将不会执行
201 return errors.WithMessagef(err, "failed list dst [%s] objs", dstActualPath)
202 }
203 for _, obj := range dstObjs {
204 if err := t.Ctx().Err(); err != nil {
205 return err
206 }
207 if !obj.IsDir() {
208 existedObjs[obj.GetName()] = true
209 }
210 }
211 }
212
213 for _, obj := range objs {
214 if err := t.Ctx().Err(); err != nil {
215 return err
216 }
217
218 if t.TaskType == merge && !obj.IsDir() && existedObjs[obj.GetName()] {
219 // skip existed file
220 continue
221 }
222
223 err = f(&FileTransferTask{
224 TaskType: t.TaskType,
225 TaskData: TaskData{
226 TaskExtension: task.TaskExtension{
227 Creator: t.Creator,
228 ApiUrl: t.ApiUrl,
229 },
230 SrcStorage: t.SrcStorage,
231 DstStorage: t.DstStorage,
232 SrcActualPath: stdpath.Join(t.SrcActualPath, obj.GetName()),
233 DstActualPath: dstActualPath,
234 SrcStorageMp: t.SrcStorageMp,
235 DstStorageMp: t.DstStorageMp,
236 },

Callers 2

RunMethod · 0.95
transferFunction · 0.95

Calls 13

GetFunction · 0.92
ListFunction · 0.92
DstPathToHookTypeAlias · 0.92
LinkFunction · 0.92
NewSeekableStreamFunction · 0.92
PutFunction · 0.92
AppendPayloadMethod · 0.80
ErrMethod · 0.80
SetTotalBytesMethod · 0.80
IsDirMethod · 0.65
GetNameMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected