From d3a251e6d9df0e3db3e382e99304e274be832c21 Mon Sep 17 00:00:00 2001 From: Roman Zaynetdinov Date: Thu, 17 Nov 2016 17:12:41 +0200 Subject: [PATCH] lib/model: Log folder IDs and labels (fixes #3724) GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/3741 --- lib/config/folderconfiguration.go | 5 +++++ lib/model/model.go | 32 +++++++++++++++---------------- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/lib/config/folderconfiguration.go b/lib/config/folderconfiguration.go index 355b31e1a..a1d8aed7c 100644 --- a/lib/config/folderconfiguration.go +++ b/lib/config/folderconfiguration.go @@ -7,6 +7,7 @@ package config import ( + "fmt" "os" "path/filepath" "runtime" @@ -103,6 +104,10 @@ func (f *FolderConfiguration) HasMarker() bool { return true } +func (f FolderConfiguration) Description() string { + return fmt.Sprintf("%q (%s)", f.Label, f.ID) +} + func (f *FolderConfiguration) DeviceIDs() []protocol.DeviceID { deviceIDs := make([]protocol.DeviceID, len(f.Devices)) for i, n := range f.Devices { diff --git a/lib/model/model.go b/lib/model/model.go index 64bc878ec..bd1753707 100644 --- a/lib/model/model.go +++ b/lib/model/model.go @@ -189,12 +189,12 @@ func (m *Model) StartFolder(folder string) { func (m *Model) startFolderLocked(folder string) config.FolderType { cfg, ok := m.folderCfgs[folder] if !ok { - panic("cannot start nonexistent folder " + folder) + panic("cannot start nonexistent folder " + cfg.Description()) } _, ok = m.folderRunners[folder] if ok { - panic("cannot start already running folder " + folder) + panic("cannot start already running folder " + cfg.Description()) } folderFactory, ok := folderFactories[cfg.Type] @@ -806,19 +806,19 @@ func (m *Model) ClusterConfig(deviceID protocol.DeviceID, cm protocol.ClusterCon // the IndexID, or something else weird has // happened. We send a full index to reset the // situation. - l.Infof("Device %v folder %q is delta index compatible, but seems out of sync with reality", deviceID, folder.ID) + l.Infof("Device %v folder %q (%s) is delta index compatible, but seems out of sync with reality", deviceID, folder.Label, folder.ID) startSequence = 0 continue } - l.Debugf("Device %v folder %q is delta index compatible (mlv=%d)", deviceID, folder.ID, dev.MaxSequence) + l.Debugf("Device %v folder %q (%s) is delta index compatible (mlv=%d)", deviceID, folder.Label, folder.ID, dev.MaxSequence) startSequence = dev.MaxSequence } else if dev.IndexID != 0 { // They say they've seen an index ID from us, but it's // not the right one. Either they are confused or we // must have reset our database since last talking to // them. We'll start with a full index transfer. - l.Infof("Device %v folder %q has mismatching index ID for us (%v != %v)", deviceID, folder.ID, dev.IndexID, myIndexID) + l.Infof("Device %v folder %q (%s) has mismatching index ID for us (%v != %v)", deviceID, folder.Label, folder.ID, dev.IndexID, myIndexID) startSequence = 0 } } else if dev.ID == deviceID && dev.IndexID != 0 { @@ -840,7 +840,7 @@ func (m *Model) ClusterConfig(deviceID protocol.DeviceID, cm protocol.ClusterCon // will probably send us a full index. We drop any // information we have and remember this new index ID // instead. - l.Infof("Device %v folder %q has a new index ID (%v)", deviceID, folder.ID, dev.IndexID) + l.Infof("Device %v folder %q (%s) has a new index ID (%v)", deviceID, folder.Label, folder.ID, dev.IndexID) fs.Replace(deviceID, nil) fs.SetIndexID(deviceID, dev.IndexID) } else { @@ -952,7 +952,7 @@ func (m *Model) handleDeintroductions(introducerCfg config.DeviceConfiguration, // We could not find that folder shared on the // introducer with the device that was introduced to us. // We should follow and unshare aswell. - l.Infof("Unsharing folder %q with %v as introducer %v no longer shares the folder with that device", folderCfg.ID, folderCfg.Devices[i].DeviceID, folderCfg.Devices[i].IntroducedBy) + l.Infof("Unsharing folder %s with %v as introducer %v no longer shares the folder with that device", folderCfg.Description(), folderCfg.Devices[i].DeviceID, folderCfg.Devices[i].IntroducedBy) folderCfg.Devices = append(folderCfg.Devices[:i], folderCfg.Devices[i+1:]...) i-- folderChanged = true @@ -1020,7 +1020,7 @@ func (m *Model) introduceDevice(device protocol.Device, introducerCfg config.Dev } func (m *Model) introduceDeviceToFolder(device protocol.Device, folder protocol.Folder, introducerCfg config.DeviceConfiguration) { - l.Infof("Sharing folder %q with %v (vouched for by introducer %v)", folder.ID, device.ID, introducerCfg.DeviceID) + l.Infof("Sharing folder %q (%s) with %v (vouched for by introducer %v)", folder.Label, folder.ID, device.ID, introducerCfg.DeviceID) m.deviceFolders[device.ID] = append(m.deviceFolders[device.ID], folder.ID) m.folderDevices.set(device.ID, folder.ID) @@ -1735,14 +1735,14 @@ func (m *Model) internalScanFolderSubdirs(folder string, subDirs []string) error if err := m.CheckFolderHealth(folder); err != nil { runner.setError(err) - l.Infof("Stopping folder %s due to error: %s", folder, err) + l.Infof("Stopping folder %s due to error: %s", folderCfg.Description(), err) return err } if err := ignores.Load(filepath.Join(folderCfg.Path(), ".stignore")); err != nil && !os.IsNotExist(err) { err = fmt.Errorf("loading ignores: %v", err) runner.setError(err) - l.Infof("Stopping folder %s due to error: %s", folder, err) + l.Infof("Stopping folder %s due to error: %s", folderCfg.Description(), err) return err } @@ -1799,7 +1799,7 @@ func (m *Model) internalScanFolderSubdirs(folder string, subDirs []string) error for f := range fchan { if len(batch) == batchSizeFiles || blocksHandled > batchSizeBlocks { if err := m.CheckFolderHealth(folder); err != nil { - l.Infof("Stopping folder %s mid-scan due to folder error: %s", folder, err) + l.Infof("Stopping folder %s mid-scan due to folder error: %s", folderCfg.Description(), err) return err } m.updateLocalsFromScanning(folder, batch) @@ -1811,7 +1811,7 @@ func (m *Model) internalScanFolderSubdirs(folder string, subDirs []string) error } if err := m.CheckFolderHealth(folder); err != nil { - l.Infof("Stopping folder %s mid-scan due to folder error: %s", folder, err) + l.Infof("Stopping folder %s mid-scan due to folder error: %s", folderCfg.Description(), err) return err } else if len(batch) > 0 { m.updateLocalsFromScanning(folder, batch) @@ -1887,13 +1887,13 @@ func (m *Model) internalScanFolderSubdirs(folder string, subDirs []string) error }) if iterError != nil { - l.Infof("Stopping folder %s mid-scan due to folder error: %s", folder, iterError) + l.Infof("Stopping folder %s mid-scan due to folder error: %s", folderCfg.Description(), iterError) return iterError } } if err := m.CheckFolderHealth(folder); err != nil { - l.Infof("Stopping folder %s mid-scan due to folder error: %s", folder, err) + l.Infof("Stopping folder %s mid-scan due to folder error: %s", folderCfg.Description(), err) return err } else if len(batch) > 0 { m.updateLocalsFromScanning(folder, batch) @@ -2291,9 +2291,9 @@ func (m *Model) runnerExchangeError(folder config.FolderConfiguration, err error if err != nil { if oldErr != nil && oldErr.Error() != err.Error() { - l.Infof("Folder %q error changed: %q -> %q", folder.ID, oldErr, err) + l.Infof("Folder %s error changed: %q -> %q", folder.Description(), oldErr, err) } else if oldErr == nil { - l.Warnf("Stopping folder %q - %v", folder.ID, err) + l.Warnf("Stopping folder %s - %v", folder.Description(), err) } if runnerExists { runner.setError(err)