From b43eccf2feb79a4ab8c5a376da8570ff415833d7 Mon Sep 17 00:00:00 2001 From: Simon Frei Date: Fri, 20 Nov 2020 14:13:50 +0100 Subject: [PATCH] lib/model: Never send unpaused folder without index info (#7134) --- lib/model/model.go | 12 +++++++----- lib/model/model_test.go | 28 ++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/lib/model/model.go b/lib/model/model.go index 12286eef8..d1769584b 100644 --- a/lib/model/model.go +++ b/lib/model/model.go @@ -2187,13 +2187,15 @@ func (m *model) generateClusterConfig(device protocol.DeviceID) protocol.Cluster IgnorePermissions: folderCfg.IgnorePerms, IgnoreDelete: folderCfg.IgnoreDelete, DisableTempIndexes: folderCfg.DisableTempIndexes, - Paused: folderCfg.Paused, } - var fs *db.FileSet - if !folderCfg.Paused { - fs = m.folderFiles[folderCfg.ID] - } + fs := m.folderFiles[folderCfg.ID] + + // Even if we aren't paused, if we haven't started the folder yet + // pretend we are. Otherwise the remote might get confused about + // the missing index info (and drop all the info). We will send + // another cluster config once the folder is started. + protocolFolder.Paused = folderCfg.Paused || fs == nil for _, device := range folderCfg.Devices { deviceCfg, _ := m.cfg.Device(device.DeviceID) diff --git a/lib/model/model_test.go b/lib/model/model_test.go index ae9487868..2293ea8ba 100644 --- a/lib/model/model_test.go +++ b/lib/model/model_test.go @@ -4341,6 +4341,34 @@ func TestCcCheckEncryption(t *testing.T) { } } +func TestCCFolderNotRunning(t *testing.T) { + // Create the folder, but don't start it. + w, fcfg := tmpDefaultWrapper() + tfs := fcfg.Filesystem() + m := newModel(w, myID, "syncthing", "dev", db.NewLowlevel(backend.OpenMemory()), nil) + defer cleanupModelAndRemoveDir(m, tfs.URI()) + + // A connection can happen before all the folders are started. + cc := m.generateClusterConfig(device1) + if l := len(cc.Folders); l != 1 { + t.Fatalf("Expected 1 folder in CC, got %v", l) + } + folder := cc.Folders[0] + if id := folder.ID; id != fcfg.ID { + t.Fatalf("Expected folder %v, got %v", fcfg.ID, id) + } + if l := len(folder.Devices); l != 2 { + t.Fatalf("Expected 2 devices in CC, got %v", l) + } + local := folder.Devices[1] + if local.ID != myID { + local = folder.Devices[0] + } + if !folder.Paused && local.IndexID == 0 { + t.Errorf("Folder isn't paused, but index-id is zero") + } +} + func equalStringsInAnyOrder(a, b []string) bool { if len(a) != len(b) { return false