mirror of
https://github.com/octoleo/syncthing.git
synced 2024-12-22 19:08:58 +00:00
lib/model: Consistent error return values for folder methods on model (#6325)
This commit is contained in:
parent
04e648fee6
commit
a596e5e2f0
@ -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)
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user