From 22903df2c10b4224bc50f545f3223636d96f7d71 Mon Sep 17 00:00:00 2001 From: Simon Frei Date: Thu, 9 Feb 2017 20:29:56 +0000 Subject: [PATCH] lib/model: Meaningful error messages for paused folders GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/3977 LGTM: AudriusButkevicius, calmh --- lib/model/model.go | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/lib/model/model.go b/lib/model/model.go index 517427b73..fed996e15 100644 --- a/lib/model/model.go +++ b/lib/model/model.go @@ -106,7 +106,6 @@ var ( folderFactories = make(map[config.FolderType]folderFactory, 0) ) -// errors returned by the CheckFolderHealth method var ( errFolderPathEmpty = errors.New("folder path empty") errFolderPathMissing = errors.New("folder path missing") @@ -118,6 +117,8 @@ var ( errDevicePaused = errors.New("device is paused") errDeviceIgnored = errors.New("device is ignored") errNotRelative = errors.New("not a relative path") + errFolderPaused = errors.New("folder is paused") + errFolderMissing = errors.New("no such folder") ) // NewModel creates and starts a new model. The model starts in read-only mode, @@ -1705,14 +1706,15 @@ func (m *Model) ScanFolder(folder string) error { func (m *Model) ScanFolderSubdirs(folder string, subs []string) error { m.fmut.Lock() - runner, ok := m.folderRunners[folder] + runner, okRunner := m.folderRunners[folder] + cfg, okCfg := m.folderCfgs[folder] m.fmut.Unlock() - // Folders are added to folderRunners only when they are started. We can't - // scan them before they have started, so that's what we need to check for - // here. - if !ok { - return errors.New("no such folder") + if !okRunner { + if okCfg && cfg.Paused { + return errFolderPaused + } + return errFolderMissing } return runner.Scan(subs) @@ -1760,11 +1762,11 @@ func (m *Model) internalScanFolderSubdirs(folder string, subDirs []string) error } }() - // Folders are added to folderRunners only when they are started. We can't - // scan them before they have started, so that's what we need to check for - // here. if !ok { - return errors.New("no such folder") + if folderCfg.Paused { + return errFolderPaused + } + return errFolderMissing } if err := m.CheckFolderHealth(folder); err != nil { @@ -2248,7 +2250,7 @@ func (m *Model) BringToFront(folder, file string) { func (m *Model) CheckFolderHealth(id string) error { folder, ok := m.cfg.Folders()[id] if !ok { - return errors.New("folder does not exist") + return errFolderMissing } // Check for folder errors, with the most serious and specific first and