Fix nil pointer dereferences in REST with non-existent folders

This commit is contained in:
KAMADA Ken'ichi 2015-04-18 22:41:47 +09:00
parent a624c302ab
commit 33d3ba1b45
1 changed files with 14 additions and 3 deletions

View File

@ -769,15 +769,23 @@ func (m *Model) ReplaceLocal(folder string, fs []protocol.FileInfo) {
func (m *Model) CurrentFolderFile(folder string, file string) (protocol.FileInfo, bool) {
m.fmut.RLock()
f, ok := m.folderFiles[folder].Get(protocol.LocalDeviceID, file)
fs, ok := m.folderFiles[folder]
m.fmut.RUnlock()
if !ok {
return protocol.FileInfo{}, false
}
f, ok := fs.Get(protocol.LocalDeviceID, file)
return f, ok
}
func (m *Model) CurrentGlobalFile(folder string, file string) (protocol.FileInfo, bool) {
m.fmut.RLock()
f, ok := m.folderFiles[folder].GetGlobal(file)
fs, ok := m.folderFiles[folder]
m.fmut.RUnlock()
if !ok {
return protocol.FileInfo{}, false
}
f, ok := fs.GetGlobal(file)
return f, ok
}
@ -1347,9 +1355,12 @@ func (m *Model) State(folder string) (string, time.Time, error) {
func (m *Model) Override(folder string) {
m.fmut.RLock()
fs := m.folderFiles[folder]
fs, ok := m.folderFiles[folder]
runner := m.folderRunners[folder]
m.fmut.RUnlock()
if !ok {
return
}
runner.setState(FolderScanning)
batch := make([]protocol.FileInfo, 0, indexBatchSize)