浏览代码

Only connected devices are available devices

Audrius Butkevicius 11 年之前
父节点
当前提交
fc47562983
共有 1 个文件被更改,包括 13 次插入1 次删除
  1. 13 1
      internal/model/model.go

+ 13 - 1
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 {