mirror of
https://github.com/octoleo/syncthing.git
synced 2025-01-22 22:58:25 +00:00
lib/model: Don't include unshared folders in ClusterConfig (fixes #4926)
Also fixes a data race where ClusterConfig would access folderFiles without a lock. Tweaked the ClusterConfig unit test to verify the behavior.
This commit is contained in:
parent
616883304e
commit
2343c82c33
@ -2207,12 +2207,21 @@ func (m *Model) generateClusterConfig(device protocol.DeviceID) protocol.Cluster
|
|||||||
var message protocol.ClusterConfig
|
var message protocol.ClusterConfig
|
||||||
|
|
||||||
m.fmut.RLock()
|
m.fmut.RLock()
|
||||||
folderFiles := m.folderFiles
|
defer m.fmut.RUnlock()
|
||||||
m.fmut.RUnlock()
|
|
||||||
|
|
||||||
var fs *db.FileSet
|
|
||||||
|
|
||||||
for _, folderCfg := range m.cfg.FolderList() {
|
for _, folderCfg := range m.cfg.FolderList() {
|
||||||
|
isShared := false
|
||||||
|
for _, sharedWith := range folderCfg.Devices {
|
||||||
|
if sharedWith.DeviceID == device {
|
||||||
|
isShared = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if !isShared {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
protocolFolder := protocol.Folder{
|
protocolFolder := protocol.Folder{
|
||||||
ID: folderCfg.ID,
|
ID: folderCfg.ID,
|
||||||
Label: folderCfg.Label,
|
Label: folderCfg.Label,
|
||||||
@ -2223,8 +2232,9 @@ func (m *Model) generateClusterConfig(device protocol.DeviceID) protocol.Cluster
|
|||||||
Paused: folderCfg.Paused,
|
Paused: folderCfg.Paused,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var fs *db.FileSet
|
||||||
if !folderCfg.Paused {
|
if !folderCfg.Paused {
|
||||||
fs = folderFiles[folderCfg.ID]
|
fs = m.folderFiles[folderCfg.ID]
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, device := range folderCfg.Devices {
|
for _, device := range folderCfg.Devices {
|
||||||
@ -2239,7 +2249,7 @@ func (m *Model) generateClusterConfig(device protocol.DeviceID) protocol.Cluster
|
|||||||
Introducer: deviceCfg.Introducer,
|
Introducer: deviceCfg.Introducer,
|
||||||
}
|
}
|
||||||
|
|
||||||
if !folderCfg.Paused {
|
if fs != nil {
|
||||||
if deviceCfg.DeviceID == m.id {
|
if deviceCfg.DeviceID == m.id {
|
||||||
protocolDevice.IndexID = fs.IndexID(protocol.LocalDeviceID)
|
protocolDevice.IndexID = fs.IndexID(protocol.LocalDeviceID)
|
||||||
protocolDevice.MaxSequence = fs.Sequence(protocol.LocalDeviceID)
|
protocolDevice.MaxSequence = fs.Sequence(protocol.LocalDeviceID)
|
||||||
|
@ -607,20 +607,29 @@ func TestClusterConfig(t *testing.T) {
|
|||||||
cfg.Folders = []config.FolderConfiguration{
|
cfg.Folders = []config.FolderConfiguration{
|
||||||
{
|
{
|
||||||
ID: "folder1",
|
ID: "folder1",
|
||||||
Path: "testdata",
|
Path: "testdata1",
|
||||||
Devices: []config.FolderDeviceConfiguration{
|
Devices: []config.FolderDeviceConfiguration{
|
||||||
{DeviceID: device1},
|
{DeviceID: device1},
|
||||||
{DeviceID: device2},
|
{DeviceID: device2},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
ID: "folder2",
|
ID: "folder2",
|
||||||
Path: "testdata",
|
Path: "testdata2",
|
||||||
|
Paused: true, // should still be included
|
||||||
Devices: []config.FolderDeviceConfiguration{
|
Devices: []config.FolderDeviceConfiguration{
|
||||||
{DeviceID: device1},
|
{DeviceID: device1},
|
||||||
{DeviceID: device2},
|
{DeviceID: device2},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
ID: "folder3",
|
||||||
|
Path: "testdata3",
|
||||||
|
Devices: []config.FolderDeviceConfiguration{
|
||||||
|
{DeviceID: device1},
|
||||||
|
// should not be included, does not include device2
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
db := db.OpenMemory()
|
db := db.OpenMemory()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user