lib/model: Meaningful error messages for paused folders
GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/3977 LGTM: AudriusButkevicius, calmh
This commit is contained in:
parent
10618e80a3
commit
22903df2c1
@ -106,7 +106,6 @@ var (
|
|||||||
folderFactories = make(map[config.FolderType]folderFactory, 0)
|
folderFactories = make(map[config.FolderType]folderFactory, 0)
|
||||||
)
|
)
|
||||||
|
|
||||||
// errors returned by the CheckFolderHealth method
|
|
||||||
var (
|
var (
|
||||||
errFolderPathEmpty = errors.New("folder path empty")
|
errFolderPathEmpty = errors.New("folder path empty")
|
||||||
errFolderPathMissing = errors.New("folder path missing")
|
errFolderPathMissing = errors.New("folder path missing")
|
||||||
@ -118,6 +117,8 @@ var (
|
|||||||
errDevicePaused = errors.New("device is paused")
|
errDevicePaused = errors.New("device is paused")
|
||||||
errDeviceIgnored = errors.New("device is ignored")
|
errDeviceIgnored = errors.New("device is ignored")
|
||||||
errNotRelative = errors.New("not a relative path")
|
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,
|
// 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 {
|
func (m *Model) ScanFolderSubdirs(folder string, subs []string) error {
|
||||||
m.fmut.Lock()
|
m.fmut.Lock()
|
||||||
runner, ok := m.folderRunners[folder]
|
runner, okRunner := m.folderRunners[folder]
|
||||||
|
cfg, okCfg := m.folderCfgs[folder]
|
||||||
m.fmut.Unlock()
|
m.fmut.Unlock()
|
||||||
|
|
||||||
// Folders are added to folderRunners only when they are started. We can't
|
if !okRunner {
|
||||||
// scan them before they have started, so that's what we need to check for
|
if okCfg && cfg.Paused {
|
||||||
// here.
|
return errFolderPaused
|
||||||
if !ok {
|
}
|
||||||
return errors.New("no such folder")
|
return errFolderMissing
|
||||||
}
|
}
|
||||||
|
|
||||||
return runner.Scan(subs)
|
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 {
|
if !ok {
|
||||||
return errors.New("no such folder")
|
if folderCfg.Paused {
|
||||||
|
return errFolderPaused
|
||||||
|
}
|
||||||
|
return errFolderMissing
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := m.CheckFolderHealth(folder); err != nil {
|
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 {
|
func (m *Model) CheckFolderHealth(id string) error {
|
||||||
folder, ok := m.cfg.Folders()[id]
|
folder, ok := m.cfg.Folders()[id]
|
||||||
if !ok {
|
if !ok {
|
||||||
return errors.New("folder does not exist")
|
return errFolderMissing
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check for folder errors, with the most serious and specific first and
|
// Check for folder errors, with the most serious and specific first and
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user