All roads lead to Finisher (fixes #1201)

This commit is contained in:
Audrius Butkevicius
2015-01-07 23:12:12 +00:00
parent 5d173168cc
commit dec479532e
5 changed files with 193 additions and 34 deletions

View File

@@ -613,17 +613,17 @@ func (p *Puller) shortcutSymlink(curFile, file protocol.FileInfo) {
func (p *Puller) copierRoutine(in <-chan copyBlocksState, pullChan chan<- pullBlockState, out chan<- *sharedPullerState) {
buf := make([]byte, protocol.BlockSize)
nextFile:
for state := range in {
if p.progressEmitter != nil {
p.progressEmitter.Register(state.sharedPullerState)
}
dstFd, err := state.tempFile()
if err != nil {
// Nothing more to do for this failed file (the error was logged
// when it happened)
continue nextFile
}
if p.progressEmitter != nil {
p.progressEmitter.Register(state.sharedPullerState)
out <- state.sharedPullerState
continue
}
evictionChan := make(chan lfu.Eviction)
@@ -687,7 +687,7 @@ nextFile:
_, err = dstFd.WriteAt(buf, block.Offset)
if err != nil {
state.earlyClose("dst write", err)
state.fail("dst write", err)
}
if file == state.file.Name {
state.copiedFromOrigin()
@@ -739,9 +739,9 @@ func (p *Puller) pullerRoutine(in <-chan pullBlockState, out chan<- *sharedPulle
selected := activity.leastBusy(potentialDevices)
if selected == (protocol.DeviceID{}) {
if lastError != nil {
state.earlyClose("pull", lastError)
state.fail("pull", lastError)
} else {
state.earlyClose("pull", errNoDevice)
state.fail("pull", errNoDevice)
}
break
}
@@ -767,13 +767,13 @@ func (p *Puller) pullerRoutine(in <-chan pullBlockState, out chan<- *sharedPulle
// Save the block data we got from the cluster
_, err = fd.WriteAt(buf, state.block.Offset)
if err != nil {
state.earlyClose("save", err)
state.fail("save", err)
} else {
state.pullDone()
out <- state.sharedPullerState
}
break
}
out <- state.sharedPullerState
}
}
@@ -863,7 +863,9 @@ func (p *Puller) finisherRoutine(in <-chan *sharedPullerState) {
}
p.queue.Done(state.file.Name)
p.performFinish(state)
if state.failed() == nil {
p.performFinish(state)
}
p.model.receivedFile(p.folder, state.file.Name)
if p.progressEmitter != nil {
p.progressEmitter.Deregister(state)