|
@@ -448,7 +448,7 @@ FilesAreDifferent:
|
|
|
tempName := filepath.Join(p.dir, defTempNamer.TempName(file.Name))
|
|
tempName := filepath.Join(p.dir, defTempNamer.TempName(file.Name))
|
|
|
realName := filepath.Join(p.dir, file.Name)
|
|
realName := filepath.Join(p.dir, file.Name)
|
|
|
|
|
|
|
|
- var reuse bool
|
|
|
|
|
|
|
+ reused := 0
|
|
|
var blocks []protocol.BlockInfo
|
|
var blocks []protocol.BlockInfo
|
|
|
|
|
|
|
|
// Check for an old temporary file which might have some blocks we could
|
|
// Check for an old temporary file which might have some blocks we could
|
|
@@ -472,11 +472,10 @@ FilesAreDifferent:
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // If any blocks could be reused, let the sharedpullerstate know
|
|
|
|
|
- // which flags it is expected to set on the file.
|
|
|
|
|
- if len(blocks) != len(file.Blocks) {
|
|
|
|
|
- reuse = true
|
|
|
|
|
- } else {
|
|
|
|
|
|
|
+ // The sharedpullerstate will know which flags to use when opening the
|
|
|
|
|
+ // temp file depending if we are reusing any blocks or not.
|
|
|
|
|
+ reused = len(file.Blocks) - len(blocks)
|
|
|
|
|
+ if reused == 0 {
|
|
|
// Otherwise, discard the file ourselves in order for the
|
|
// Otherwise, discard the file ourselves in order for the
|
|
|
// sharedpuller not to panic when it fails to exlusively create a
|
|
// sharedpuller not to panic when it fails to exlusively create a
|
|
|
// file which already exists
|
|
// file which already exists
|
|
@@ -491,12 +490,13 @@ FilesAreDifferent:
|
|
|
folder: p.folder,
|
|
folder: p.folder,
|
|
|
tempName: tempName,
|
|
tempName: tempName,
|
|
|
realName: realName,
|
|
realName: realName,
|
|
|
|
|
+ copyTotal: len(blocks),
|
|
|
copyNeeded: len(blocks),
|
|
copyNeeded: len(blocks),
|
|
|
- reuse: reuse,
|
|
|
|
|
|
|
+ reused: reused,
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if debug {
|
|
if debug {
|
|
|
- l.Debugf("%v need file %s; copy %d, reuse %v", p, file.Name, len(blocks), reuse)
|
|
|
|
|
|
|
+ l.Debugf("%v need file %s; copy %d, reused %v", p, file.Name, len(blocks), reused)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
cs := copyBlocksState{
|
|
cs := copyBlocksState{
|
|
@@ -591,6 +591,9 @@ nextFile:
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
state.earlyClose("dst write", err)
|
|
state.earlyClose("dst write", err)
|
|
|
}
|
|
}
|
|
|
|
|
+ if file == state.file.Name {
|
|
|
|
|
+ state.copiedFromOrigin()
|
|
|
|
|
+ }
|
|
|
return true
|
|
return true
|
|
|
})
|
|
})
|
|
|
|
|
|
|
@@ -605,8 +608,9 @@ nextFile:
|
|
|
block: block,
|
|
block: block,
|
|
|
}
|
|
}
|
|
|
pullChan <- ps
|
|
pullChan <- ps
|
|
|
|
|
+ } else {
|
|
|
|
|
+ state.copyDone()
|
|
|
}
|
|
}
|
|
|
- state.copyDone()
|
|
|
|
|
}
|
|
}
|
|
|
fdCache.Evict(fdCache.Len())
|
|
fdCache.Evict(fdCache.Len())
|
|
|
close(evictionChan)
|
|
close(evictionChan)
|