mirror of
https://github.com/octoleo/syncthing.git
synced 2024-12-22 02:48:59 +00:00
### Purpose As discussed in #9686 Syncthing currently does not check folderstate on remote device before pulling. If no devices have a valid folderstate (i.e all devices have the folder paused) it will still attempt to pull. On large folders this will cause a hanging "Syncing" status. This checks whether at least one connected device has the file available and has a valid folderstate. ### Testing Tested locally on multiple devices. We're new to Go (all our stuff is Python) so please bear with! Interested if there may be a better place to slot this in. Thanks, Jon --------- Co-authored-by: Simon Frei <freisim93@gmail.com>
This commit is contained in:
parent
955ac7775e
commit
36ef17df8f
@ -505,13 +505,10 @@ nextFile:
|
|||||||
continue nextFile
|
continue nextFile
|
||||||
}
|
}
|
||||||
|
|
||||||
devices := snap.Availability(fileName)
|
devices := f.model.fileAvailability(f.FolderConfiguration, snap, fi)
|
||||||
for _, dev := range devices {
|
if len(devices) > 0 {
|
||||||
if f.model.ConnectedTo(dev) {
|
f.handleFile(fi, snap, copyChan)
|
||||||
// Handle the file normally, by copying and pulling, etc.
|
continue
|
||||||
f.handleFile(fi, snap, copyChan)
|
|
||||||
continue nextFile
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
f.newPullError(fileName, errNotAvailable)
|
f.newPullError(fileName, errNotAvailable)
|
||||||
f.queue.Done(fileName)
|
f.queue.Done(fileName)
|
||||||
@ -1547,7 +1544,7 @@ func (f *sendReceiveFolder) pullBlock(state pullBlockState, snap *db.Snapshot, o
|
|||||||
}
|
}
|
||||||
|
|
||||||
var lastError error
|
var lastError error
|
||||||
candidates := f.model.availabilityInSnapshot(f.FolderConfiguration, snap, state.file, state.block)
|
candidates := f.model.blockAvailability(f.FolderConfiguration, snap, state.file, state.block)
|
||||||
loop:
|
loop:
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
|
@ -2882,16 +2882,31 @@ func (m *model) Availability(folder string, file protocol.FileInfo, block protoc
|
|||||||
}
|
}
|
||||||
defer snap.Release()
|
defer snap.Release()
|
||||||
|
|
||||||
return m.availabilityInSnapshotRLocked(cfg, snap, file, block), nil
|
return m.blockAvailabilityRLocked(cfg, snap, file, block), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *model) availabilityInSnapshot(cfg config.FolderConfiguration, snap *db.Snapshot, file protocol.FileInfo, block protocol.BlockInfo) []Availability {
|
func (m *model) blockAvailability(cfg config.FolderConfiguration, snap *db.Snapshot, file protocol.FileInfo, block protocol.BlockInfo) []Availability {
|
||||||
m.mut.RLock()
|
m.mut.RLock()
|
||||||
defer m.mut.RUnlock()
|
defer m.mut.RUnlock()
|
||||||
return m.availabilityInSnapshotRLocked(cfg, snap, file, block)
|
return m.blockAvailabilityRLocked(cfg, snap, file, block)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *model) availabilityInSnapshotRLocked(cfg config.FolderConfiguration, snap *db.Snapshot, file protocol.FileInfo, block protocol.BlockInfo) []Availability {
|
func (m *model) blockAvailabilityRLocked(cfg config.FolderConfiguration, snap *db.Snapshot, file protocol.FileInfo, block protocol.BlockInfo) []Availability {
|
||||||
|
var candidates []Availability
|
||||||
|
|
||||||
|
candidates = append(candidates, m.fileAvailabilityRLocked(cfg, snap, file)...)
|
||||||
|
candidates = append(candidates, m.blockAvailabilityFromTemporaryRLocked(cfg, file, block)...)
|
||||||
|
|
||||||
|
return candidates
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *model) fileAvailability(cfg config.FolderConfiguration, snap *db.Snapshot, file protocol.FileInfo) []Availability {
|
||||||
|
m.mut.RLock()
|
||||||
|
defer m.mut.RUnlock()
|
||||||
|
return m.fileAvailabilityRLocked(cfg, snap, file)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *model) fileAvailabilityRLocked(cfg config.FolderConfiguration, snap *db.Snapshot, file protocol.FileInfo) []Availability {
|
||||||
var availabilities []Availability
|
var availabilities []Availability
|
||||||
for _, device := range snap.Availability(file.Name) {
|
for _, device := range snap.Availability(file.Name) {
|
||||||
if _, ok := m.remoteFolderStates[device]; !ok {
|
if _, ok := m.remoteFolderStates[device]; !ok {
|
||||||
@ -2905,13 +2920,16 @@ func (m *model) availabilityInSnapshotRLocked(cfg config.FolderConfiguration, sn
|
|||||||
availabilities = append(availabilities, Availability{ID: device, FromTemporary: false})
|
availabilities = append(availabilities, Availability{ID: device, FromTemporary: false})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return availabilities
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *model) blockAvailabilityFromTemporaryRLocked(cfg config.FolderConfiguration, file protocol.FileInfo, block protocol.BlockInfo) []Availability {
|
||||||
|
var availabilities []Availability
|
||||||
for _, device := range cfg.Devices {
|
for _, device := range cfg.Devices {
|
||||||
if m.deviceDownloads[device.DeviceID].Has(cfg.ID, file.Name, file.Version, int(block.Offset/int64(file.BlockSize()))) {
|
if m.deviceDownloads[device.DeviceID].Has(cfg.ID, file.Name, file.Version, int(block.Offset/int64(file.BlockSize()))) {
|
||||||
availabilities = append(availabilities, Availability{ID: device.DeviceID, FromTemporary: true})
|
availabilities = append(availabilities, Availability{ID: device.DeviceID, FromTemporary: true})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return availabilities
|
return availabilities
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user