MCPcopy
hub / github.com/rclone/rclone / run

Method run

backend/cache/handle.go:562–630  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

560}
561
562func (b *backgroundWriter) run() {
563 state := 0
564 for {
565 b.mu.Lock()
566 b.running = true
567 b.mu.Unlock()
568 select {
569 case s := <-b.stateCh:
570 state = s
571 default:
572 //
573 }
574 switch state {
575 case 1:
576 runtime.Gosched()
577 time.Sleep(time.Millisecond * 500)
578 continue
579 case 2:
580 return
581 }
582
583 absPath, err := b.fs.cache.getPendingUpload(b.fs.Root(), time.Duration(b.fs.opt.TempWaitTime))
584 if err != nil || absPath == "" || !b.fs.isRootInPath(absPath) {
585 time.Sleep(time.Second)
586 continue
587 }
588
589 remote := b.fs.cleanRootFromPath(absPath)
590 b.notify(remote, BackgroundUploadStarted, nil)
591 fs.Infof(remote, "background upload: started upload")
592 err = operations.MoveFile(context.TODO(), b.fs.UnWrap(), b.fs.tempFs, remote, remote)
593 if err != nil {
594 b.notify(remote, BackgroundUploadError, err)
595 _ = b.fs.cache.rollbackPendingUpload(absPath)
596 fs.Errorf(remote, "background upload: %v", err)
597 continue
598 }
599 // clean empty dirs up to root
600 thisDir := cleanPath(path.Dir(remote))
601 for thisDir != "" {
602 thisList, err := b.fs.tempFs.List(context.TODO(), thisDir)
603 if err != nil {
604 break
605 }
606 if len(thisList) > 0 {
607 break
608 }
609 err = b.fs.tempFs.Rmdir(context.TODO(), thisDir)
610 fs.Debugf(thisDir, "cleaned from temp path")
611 if err != nil {
612 break
613 }
614 thisDir = cleanPath(path.Dir(thisDir))
615 }
616 fs.Infof(remote, "background upload: uploaded entry")
617 err = b.fs.cache.removePendingUpload(absPath)
618 if err != nil && !strings.Contains(err.Error(), "pending upload not found") {
619 fs.Errorf(remote, "background upload: %v", err)

Callers

nothing calls this directly

Calls 15

notifyMethod · 0.95
InfofFunction · 0.92
MoveFileFunction · 0.92
ErrorfFunction · 0.92
DebugfFunction · 0.92
cleanPathFunction · 0.85
getPendingUploadMethod · 0.80
isRootInPathMethod · 0.80
cleanRootFromPathMethod · 0.80
rollbackPendingUploadMethod · 0.80
DirMethod · 0.80
removePendingUploadMethod · 0.80

Tested by

no test coverage detected