diff --git a/lib/model/folder_recvonly_test.go b/lib/model/folder_recvonly_test.go index e2eb00726..943efba98 100644 --- a/lib/model/folder_recvonly_test.go +++ b/lib/model/folder_recvonly_test.go @@ -48,7 +48,11 @@ func TestRecvOnlyRevertDeletes(t *testing.T) { m.Index(device1, "ro", knownFiles) f.updateLocalsFromScanning(knownFiles) - size := globalSize(t, m, "ro") + m.fmut.RLock() + snap := m.folderFiles["ro"].Snapshot() + m.fmut.RUnlock() + size := snap.GlobalSize() + snap.Release() if size.Files != 1 || size.Directories != 1 { t.Fatalf("Global: expected 1 file and 1 directory: %+v", size) } diff --git a/lib/model/model.go b/lib/model/model.go index f0b6b0e2d..217c7294c 100644 --- a/lib/model/model.go +++ b/lib/model/model.go @@ -840,10 +840,11 @@ func (m *model) Completion(device protocol.DeviceID, folder string) FolderComple // DBSnapshot returns a snapshot of the database content relevant to the given folder. func (m *model) DBSnapshot(folder string) (*db.Snapshot, error) { m.fmut.RLock() - rf, ok := m.folderFiles[folder] + err := m.checkFolderRunningLocked(folder) + rf := m.folderFiles[folder] m.fmut.RUnlock() - if !ok { - return nil, errFolderMissing + if err != nil { + return nil, err } return rf.Snapshot(), nil } @@ -2319,10 +2320,11 @@ func (m *model) GlobalDirectoryTree(folder, prefix string, levels int, dirsonly func (m *model) GetFolderVersions(folder string) (map[string][]versioner.FileVersion, error) { m.fmut.RLock() - ver, ok := m.folderVersioners[folder] + err := m.checkFolderRunningLocked(folder) + ver := m.folderVersioners[folder] m.fmut.RUnlock() - if !ok { - return nil, errFolderMissing + if err != nil { + return nil, err } if ver == nil { return nil, errNoVersioner @@ -2332,16 +2334,13 @@ func (m *model) GetFolderVersions(folder string) (map[string][]versioner.FileVer } func (m *model) RestoreFolderVersions(folder string, versions map[string]time.Time) (map[string]string, error) { - fcfg, ok := m.cfg.Folder(folder) - if !ok { - return nil, errFolderMissing - } - m.fmut.RLock() + err := m.checkFolderRunningLocked(folder) + fcfg := m.folderCfgs[folder] ver := m.folderVersioners[folder] m.fmut.RUnlock() - if !ok { - return nil, errFolderMissing + if err != nil { + return nil, err } if ver == nil { return nil, errNoVersioner diff --git a/lib/model/model_test.go b/lib/model/model_test.go index 62d9e1ff6..36d3e1cde 100644 --- a/lib/model/model_test.go +++ b/lib/model/model_test.go @@ -3479,3 +3479,35 @@ func TestNewLimitedRequestResponse(t *testing.T) { t.Error("Bytes weren't returned in a timely fashion") } } + +func TestFolderAPIErrors(t *testing.T) { + wcfg, fcfg := tmpDefaultWrapper() + fcfg.Paused = true + wcfg.SetFolder(fcfg) + m := setupModel(wcfg) + defer cleanupModel(m) + + methods := []func(folder string) error{ + m.ScanFolder, + func(folder string) error { + return m.ScanFolderSubdirs(folder, nil) + }, + func(folder string) error { + _, err := m.GetFolderVersions(folder) + return err + }, + func(folder string) error { + _, err := m.RestoreFolderVersions(folder, nil) + return err + }, + } + + for i, method := range methods { + if err := method(fcfg.ID); err != ErrFolderPaused { + t.Errorf(`Expected "%v", got "%v" (method no %v)`, ErrFolderPaused, err, i) + } + if err := method("notexisting"); err != errFolderMissing { + t.Errorf(`Expected "%v", got "%v" (method no %v)`, errFolderMissing, err, i) + } + } +}