From 0f28626bb496dcf069db829a25f902f279d05d43 Mon Sep 17 00:00:00 2001 From: Jakob Borg Date: Mon, 25 Jul 2016 10:42:17 +0000 Subject: [PATCH] cmd/syncthing: Generate FolderCompletion events for folders shared with a connecting device (fixes #3436) This used to happen by itself as the connecting device always sent an Index message and we triggered on that. Nowadays there's no guarantee for that, but we anyway need to send out one event to let listeners know the state of folders shared with the device. GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/3438 --- cmd/syncthing/summaryservice.go | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/cmd/syncthing/summaryservice.go b/cmd/syncthing/summaryservice.go index 19bb2fa9b..3382a45fc 100644 --- a/cmd/syncthing/summaryservice.go +++ b/cmd/syncthing/summaryservice.go @@ -10,6 +10,7 @@ import ( "time" "github.com/syncthing/syncthing/lib/events" + "github.com/syncthing/syncthing/lib/protocol" "github.com/syncthing/syncthing/lib/sync" "github.com/thejerf/suture" ) @@ -59,7 +60,7 @@ func (c *folderSummaryService) Stop() { // listenForUpdates subscribes to the event bus and makes note of folders that // need their data recalculated. func (c *folderSummaryService) listenForUpdates() { - sub := events.Default.Subscribe(events.LocalIndexUpdated | events.RemoteIndexUpdated | events.StateChanged | events.RemoteDownloadProgress) + sub := events.Default.Subscribe(events.LocalIndexUpdated | events.RemoteIndexUpdated | events.StateChanged | events.RemoteDownloadProgress | events.DeviceConnected) defer events.Default.Unsubscribe(sub) for { @@ -67,8 +68,31 @@ func (c *folderSummaryService) listenForUpdates() { select { case ev := <-sub.C(): - // Whenever the local or remote index is updated for a given - // folder we make a note of it. + if ev.Type == events.DeviceConnected { + // When a device connects we schedule a refresh of all + // folders shared with that device. + + data := ev.Data.(map[string]string) + deviceID, _ := protocol.DeviceIDFromString(data["id"]) + + c.foldersMut.Lock() + nextFolder: + for _, folder := range c.cfg.Folders() { + for _, dev := range folder.Devices { + if dev.DeviceID == deviceID { + c.folders[folder.ID] = struct{}{} + continue nextFolder + } + } + } + c.foldersMut.Unlock() + + continue + } + + // The other events all have a "folder" attribute that they + // affect. Whenever the local or remote index is updated for a + // given folder we make a note of it. data := ev.Data.(map[string]interface{}) folder := data["folder"].(string)