Skip to content

Commit b19a612

Browse files
committed
fix: fix sync paste dir out bug, add time to task log for debug, and syncbuffertofile chunk size up to 8MB
1 parent a88ccfa commit b19a612

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

pkg/drives/sync.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -337,11 +337,12 @@ func (rs *SyncResourceService) PasteDirFrom(task *pool.Task, fs afero.Fs, srcFil
337337
fsrc := filepath.Join(src, item.Name)
338338
fdst := filepath.Join(fdstBase, item.Name)
339339

340+
klog.Infof("~~~Debug log: srcUri=%s, fsrc=%s", srcUri, fsrc)
340341
fsrcFileParam := &models.FileParam{
341342
Owner: srcFileParam.Owner,
342343
FileType: srcFileParam.FileType,
343344
Extend: srcFileParam.Extend,
344-
Path: strings.TrimPrefix(fsrc, strings.TrimPrefix(srcUri, "/data")),
345+
Path: strings.TrimPrefix("/sync"+fsrc, strings.TrimPrefix(srcUri, "/data")),
345346
}
346347
klog.Infof("~~~Debug log: dstUri=%s, fdst=%s", dstUri, fdst)
347348
fdstFileParam := &models.FileParam{
@@ -1127,9 +1128,10 @@ func SyncFileToBuffer(task *pool.Task, src, bufferFilePath string, srcFileParam
11271128
//}
11281129

11291130
repoID := srcFileParam.Extend
1130-
prefix, filename := filepath.Split(srcFileParam.Path)
1131+
prefix, filename := filepath.Split(strings.Trim(srcFileParam.Path, "/"))
11311132

1132-
dlUrl := "http://127.0.0.1:80/seahub/lib/" + repoID + "/file/" + common.EscapeURLWithSpace(prefix+filename) + "/" + "?dl=1"
1133+
dlUrl := "http://127.0.0.1:80/seahub/lib/" + repoID + "/file/" + prefix + "/" + filename + "/" + "?dl=1"
1134+
klog.Infof("~~~Debug log: dlURL=%s", dlUrl)
11331135

11341136
request, err := http.NewRequestWithContext(task.Ctx, "GET", dlUrl, nil)
11351137
if err != nil {
@@ -1209,7 +1211,7 @@ func SyncFileToBuffer(task *pool.Task, src, bufferFilePath string, srcFileParam
12091211
}
12101212

12111213
if lastProgress != progress {
1212-
task.Log = append(task.Log, fmt.Sprintf("downloaded from seafile %d/%d with progress %d", totalRead, diskSize, progress))
1214+
task.Log = append(task.Log, "["+time.Now().Format("2006-01-02 15:04:05")+"]"+fmt.Sprintf("downloaded from seafile %d/%d with progress %d", totalRead, diskSize, progress))
12131215
lastProgress = progress
12141216
}
12151217
task.Progress = mappedProgress
@@ -1321,7 +1323,7 @@ func SyncBufferToFile(task *pool.Task, bufferFilePath, dst string, dstFileParam
13211323
}
13221324
fileSize := fileInfo.Size()
13231325

1324-
chunkSize := int64(5 * 1024 * 1024) // 5 MB
1326+
chunkSize := int64(8 * 1024 * 1024) // 8MB
13251327
totalChunks := (fileSize + chunkSize - 1) / chunkSize
13261328
identifier := generateUniqueIdentifier(common.EscapeAndJoin(filename, "/"))
13271329

pkg/fileutils/rsync.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ func ExecuteRsync(task *pool.Task, src, dst string, progressLeft, progressRight
406406
if firstErr != nil {
407407
if task.Status != "failed" {
408408
errMsg := parseRsyncError(firstErr, task)
409-
task.Log = append(task.Log, errMsg)
409+
task.Log = append(task.Log, "["+time.Now().Format("2006-01-02 15:04:05")+"]"+errMsg)
410410
task.FailedReason = errMsg
411411
pool.FailTask(task.ID)
412412
}

pkg/pool/worker_pool.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ func (t *Task) UpdateProgress() {
179179
return
180180
}
181181
if log != "" {
182-
t.Log = append(t.Log, log)
182+
t.Log = append(t.Log, "["+time.Now().Format("2006-01-02 15:04:05")+"]"+log)
183183
klog.Infof("[%s] Log collected: %s (total: %d)", t.ID, log, len(t.Log))
184184
}
185185
case <-t.Ctx.Done():
@@ -235,7 +235,7 @@ func (t *Task) UpdateProgress() {
235235
break
236236
}
237237
klog.Errorf("[%s Error] %v", t.ID, err)
238-
t.Log = append(t.Log, fmt.Sprintf("ERROR: %v", err))
238+
t.Log = append(t.Log, "["+time.Now().Format("2006-01-02 15:04:05")+"]"+fmt.Sprintf("ERROR: %v", err))
239239
t.FailedReason = err.Error()
240240

241241
case progress, ok := <-t.ProgressChan:
@@ -296,12 +296,12 @@ func (t *Task) UpdateProgress() {
296296

297297
func (t *Task) Logging(entry string) {
298298
klog.Infof("TASK LOGGING [%s] %s", t.ID, entry)
299-
t.Log = append(t.Log, entry)
299+
t.Log = append(t.Log, "["+time.Now().Format("2006-01-02 15:04:05")+"]"+entry)
300300
}
301301

302302
func (t *Task) LoggingError(entry string) {
303303
klog.Infof("TASK LOGGING ERROR [%s] %s", t.ID, entry)
304-
t.Log = append(t.Log, "[ERROR] "+entry)
304+
t.Log = append(t.Log, "["+time.Now().Format("2006-01-02 15:04:05")+"]"+"[ERROR] "+entry)
305305
t.FailedReason = entry
306306
}
307307

0 commit comments

Comments
 (0)