Browse Source

lib/model: Meaningful error messages for paused folders

GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/3977
LGTM: AudriusButkevicius, calmh
Simon Frei 8 years ago
parent
commit
22903df2c1
1 changed files with 14 additions and 12 deletions
  1. 14 12
      lib/model/model.go

+ 14 - 12
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