From fc4756298355c35b56b2104e293974b8a6935284 Mon Sep 17 00:00:00 2001 From: Audrius Butkevicius Date: Fri, 31 Oct 2014 23:41:18 +0000 Subject: [PATCH] Only connected devices are available devices --- internal/model/model.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/internal/model/model.go b/internal/model/model.go index bb08f3262..2650e9ee4 100644 --- a/internal/model/model.go +++ b/internal/model/model.go @@ -1273,6 +1273,11 @@ func (m *Model) RemoteLocalVersion(folder string) uint64 { } func (m *Model) availability(folder string, file string) []protocol.DeviceID { + // Acquire this lock first, as the value returned from foldersFiles can + // gen heavily modified on Close() + m.pmut.RLock() + defer m.pmut.RUnlock() + m.fmut.RLock() fs, ok := m.folderFiles[folder] m.fmut.RUnlock() @@ -1280,7 +1285,14 @@ func (m *Model) availability(folder string, file string) []protocol.DeviceID { return nil } - return fs.Availability(file) + availableDevices := []protocol.DeviceID{} + for _, device := range fs.Availability(file) { + _, ok := m.protoConn[device] + if ok { + availableDevices = append(availableDevices, device) + } + } + return availableDevices } func (m *Model) String() string {