MCPcopy
hub / github.com/syncthing/syncthing / finisherRoutine

Method finisherRoutine

lib/model/folder_sendrecv.go:1712–1753  ·  view source on GitHub ↗
(ctx context.Context, in <-chan *sharedPullerState, dbUpdateChan chan<- dbUpdateJob, scanChan chan<- string)

Source from the content-addressed store, hash-verified

1710}
1711
1712func (f *sendReceiveFolder) finisherRoutine(ctx context.Context, in <-chan *sharedPullerState, dbUpdateChan chan<- dbUpdateJob, scanChan chan<- string) {
1713 for state := range in {
1714 if closed, err := state.finalClose(); closed {
1715 f.sl.DebugContext(ctx, "Closing temp file", slogutil.FilePath(state.file.Name))
1716
1717 f.queue.Done(state.file.Name)
1718
1719 if err == nil {
1720 err = f.performFinish(state.file, state.curFile, state.hasCurFile, state.tempName, dbUpdateChan, scanChan)
1721 }
1722
1723 if err != nil {
1724 f.newPullError(state.file.Name, fmt.Errorf("finishing: %w", err))
1725 } else {
1726 slog.InfoContext(ctx, "Synced file", f.LogAttr(), state.file.LogAttr(), slog.Group("blocks", slog.Int("local", state.reused+state.copyTotal), slog.Int("download", state.pullTotal)))
1727
1728 minBlocksPerBlock := state.file.BlockSize() / protocol.MinBlockSize
1729 blockStatsMut.Lock()
1730 blockStats["total"] += (state.reused + state.copyTotal + state.pullTotal) * minBlocksPerBlock
1731 blockStats["reused"] += state.reused * minBlocksPerBlock
1732 blockStats["pulled"] += state.pullTotal * minBlocksPerBlock
1733 // copyOriginShifted is counted towards copyOrigin due to progress bar reasons
1734 // for reporting reasons we want to separate these.
1735 blockStats["copyOrigin"] += state.copyOrigin * minBlocksPerBlock
1736 blockStats["copyElsewhere"] += (state.copyTotal - state.copyOrigin) * minBlocksPerBlock
1737 blockStatsMut.Unlock()
1738 }
1739
1740 if f.Type != config.FolderTypeReceiveEncrypted {
1741 f.model.progressEmitter.Deregister(state)
1742 }
1743
1744 f.evLogger.Log(events.ItemFinished, map[string]interface{}{
1745 "folder": f.folderID,
1746 "item": state.file.Name,
1747 "error": events.Error(err),
1748 "type": "file",
1749 "action": "update",
1750 })
1751 }
1752 }
1753}
1754
1755// Moves the given filename to the front of the job queue
1756func (f *sendReceiveFolder) BringToFront(filename string) {

Callers 4

pullerIterationMethod · 0.95
TestCopyOwnerFunction · 0.80

Calls 12

performFinishMethod · 0.95
newPullErrorMethod · 0.95
FilePathFunction · 0.92
ErrorFunction · 0.92
finalCloseMethod · 0.80
DoneMethod · 0.80
UnlockMethod · 0.80
DeregisterMethod · 0.80
GroupMethod · 0.65
LogMethod · 0.65
LogAttrMethod · 0.45
BlockSizeMethod · 0.45

Tested by 3

TestCopyOwnerFunction · 0.64