MCPcopy Create free account
hub / github.com/VirtualHotBar/NetMount / runTask

Function runTask

src/controller/task/runner.ts:5–145  ·  view source on GitHub ↗
(task: TaskListItem)

Source from the content-addressed store, hash-verified

3import { copyDir, copyFile, delDir, delFile, moveDir, moveFile, sync } from '../storage/storage'
4
5async function runTask(task: TaskListItem): Promise<TaskListItem> {
6 let taskMsg: string = task.runInfo.msg || ''
7
8 const executeTask = async (task: TaskListItem) => {
9 console.log(`Executing ${task.taskType} task: ${task.name}`)
10
11 const srcIsDir = task.source.path.endsWith('/')
12 const targetIsDir = task.target.path.endsWith('/')
13
14 /* if (item.isMove) {
15 if (item.isDir) {
16 moveDir(item.storageName, item.path, storageName!, path!);
17 } else {
18 moveFile(item.storageName, item.path, storageName!, path!);
19 }
20 } else {
21 if (item.isDir) {
22 copyDir(item.storageName, item.path, storageName!, path!);
23 } else {
24 copyFile(item.storageName, item.path, storageName!, path!)
25 }
26 } */
27
28 switch (task.taskType) {
29 case 'copy': {
30 //复制
31 if (srcIsDir && targetIsDir) {
32 //复制目录
33 await copyDir(
34 task.source.storageName,
35 task.source.path,
36 task.target.storageName,
37 task.target.path
38 )
39 } else if (!srcIsDir && !targetIsDir) {
40 //复制文件
41 await copyFile(
42 task.source.storageName,
43 task.source.path,
44 task.target.storageName,
45 task.target.path,
46 true
47 )
48 } else if (!srcIsDir && targetIsDir) {
49 //复制文件到目录
50 await copyFile(
51 task.source.storageName,
52 task.source.path,
53 task.target.storageName,
54 task.target.path
55 )
56 } else {
57 throw new Error('The directory cannot be copied/moved to a file')
58 }
59 break
60 }
61 case 'move': {
62 //移动

Callers 1

executeTaskMethod · 0.90

Calls 1

executeTaskFunction · 0.85

Tested by

no test coverage detected