lib/model: Minor cleanups

GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/3765
This commit is contained in:
Lars K.W. Gohlke 2016-12-06 08:54:04 +00:00 committed by Jakob Borg
parent 0dcf2f1bc8
commit 8ce9b026e9

View File

@ -443,7 +443,7 @@ func (m *Model) ConnectionStats() map[string]interface{} {
// DeviceStatistics returns statistics about each device // DeviceStatistics returns statistics about each device
func (m *Model) DeviceStatistics() map[string]stats.DeviceStatistics { func (m *Model) DeviceStatistics() map[string]stats.DeviceStatistics {
var res = make(map[string]stats.DeviceStatistics) res := make(map[string]stats.DeviceStatistics)
for id := range m.cfg.Devices() { for id := range m.cfg.Devices() {
res[id.String()] = m.deviceStatRef(id).GetStatistics() res[id.String()] = m.deviceStatRef(id).GetStatistics()
} }
@ -452,7 +452,7 @@ func (m *Model) DeviceStatistics() map[string]stats.DeviceStatistics {
// FolderStatistics returns statistics about each folder // FolderStatistics returns statistics about each folder
func (m *Model) FolderStatistics() map[string]stats.FolderStatistics { func (m *Model) FolderStatistics() map[string]stats.FolderStatistics {
var res = make(map[string]stats.FolderStatistics) res := make(map[string]stats.FolderStatistics)
for id := range m.cfg.Folders() { for id := range m.cfg.Folders() {
res[id] = m.folderStatRef(id).GetStatistics() res[id] = m.folderStatRef(id).GetStatistics()
} }
@ -543,7 +543,6 @@ func addSizeOfFile(s *db.Counts, f db.FileIntf) {
s.Files++ s.Files++
} }
s.Bytes += f.FileSize() s.Bytes += f.FileSize()
return
} }
// GlobalSize returns the number of files, deleted files and total bytes for all // GlobalSize returns the number of files, deleted files and total bytes for all
@ -679,16 +678,16 @@ func (m *Model) Index(deviceID protocol.DeviceID, folder string, fs []protocol.F
runner := m.folderRunners[folder] runner := m.folderRunners[folder]
m.fmut.RUnlock() m.fmut.RUnlock()
if !ok {
l.Fatalf("Index for nonexistent folder %q", folder)
}
if runner != nil { if runner != nil {
// Runner may legitimately not be set if this is the "cleanup" Index // Runner may legitimately not be set if this is the "cleanup" Index
// message at startup. // message at startup.
defer runner.IndexUpdated() defer runner.IndexUpdated()
} }
if !ok {
l.Fatalf("Index for nonexistent folder %q", folder)
}
m.pmut.RLock() m.pmut.RLock()
m.deviceDownloads[deviceID].Update(folder, makeForgetUpdate(fs)) m.deviceDownloads[deviceID].Update(folder, makeForgetUpdate(fs))
m.pmut.RUnlock() m.pmut.RUnlock()
@ -740,8 +739,9 @@ func (m *Model) IndexUpdate(deviceID protocol.DeviceID, folder string, fs []prot
func (m *Model) folderSharedWith(folder string, deviceID protocol.DeviceID) bool { func (m *Model) folderSharedWith(folder string, deviceID protocol.DeviceID) bool {
m.fmut.RLock() m.fmut.RLock()
defer m.fmut.RUnlock() shared := m.folderSharedWithLocked(folder, deviceID)
return m.folderSharedWithLocked(folder, deviceID) m.fmut.RUnlock()
return shared
} }
func (m *Model) folderSharedWithLocked(folder string, deviceID protocol.DeviceID) bool { func (m *Model) folderSharedWithLocked(folder string, deviceID protocol.DeviceID) bool {
@ -1156,8 +1156,7 @@ func (m *Model) CurrentFolderFile(folder string, file string) (protocol.FileInfo
if !ok { if !ok {
return protocol.FileInfo{}, false return protocol.FileInfo{}, false
} }
f, ok := fs.Get(protocol.LocalDeviceID, file) return fs.Get(protocol.LocalDeviceID, file)
return f, ok
} }
func (m *Model) CurrentGlobalFile(folder string, file string) (protocol.FileInfo, bool) { func (m *Model) CurrentGlobalFile(folder string, file string) (protocol.FileInfo, bool) {
@ -1167,8 +1166,7 @@ func (m *Model) CurrentGlobalFile(folder string, file string) (protocol.FileInfo
if !ok { if !ok {
return protocol.FileInfo{}, false return protocol.FileInfo{}, false
} }
f, ok := fs.GetGlobal(file) return fs.GetGlobal(file)
return f, ok
} }
type cFiler struct { type cFiler struct {