mirror of
https://github.com/octoleo/syncthing.git
synced 2024-11-12 16:26:37 +00:00
lib/model, cmd/syncthing: Also account for deleted files in folder summary events (ref #3496)
This should probably be reflected in the GUI somewhere as well...
This commit is contained in:
parent
5b37d0356c
commit
69b7f26e4c
@ -71,7 +71,7 @@ type modelIntf interface {
|
|||||||
Completion(device protocol.DeviceID, folder string) model.FolderCompletion
|
Completion(device protocol.DeviceID, folder string) model.FolderCompletion
|
||||||
Override(folder string)
|
Override(folder string)
|
||||||
NeedFolderFiles(folder string, page, perpage int) ([]db.FileInfoTruncated, []db.FileInfoTruncated, []db.FileInfoTruncated, int)
|
NeedFolderFiles(folder string, page, perpage int) ([]db.FileInfoTruncated, []db.FileInfoTruncated, []db.FileInfoTruncated, int)
|
||||||
NeedSize(folder string) (nfiles int, bytes int64)
|
NeedSize(folder string) (nfiles, ndeletes int, bytes int64)
|
||||||
ConnectionStats() map[string]interface{}
|
ConnectionStats() map[string]interface{}
|
||||||
DeviceStatistics() map[string]stats.DeviceStatistics
|
DeviceStatistics() map[string]stats.DeviceStatistics
|
||||||
FolderStatistics() map[string]stats.FolderStatistics
|
FolderStatistics() map[string]stats.FolderStatistics
|
||||||
@ -609,8 +609,8 @@ func folderSummary(cfg configIntf, m modelIntf, folder string) map[string]interf
|
|||||||
localFiles, localDeleted, localBytes := m.LocalSize(folder)
|
localFiles, localDeleted, localBytes := m.LocalSize(folder)
|
||||||
res["localFiles"], res["localDeleted"], res["localBytes"] = localFiles, localDeleted, localBytes
|
res["localFiles"], res["localDeleted"], res["localBytes"] = localFiles, localDeleted, localBytes
|
||||||
|
|
||||||
needFiles, needBytes := m.NeedSize(folder)
|
needFiles, needDeletes, needBytes := m.NeedSize(folder)
|
||||||
res["needFiles"], res["needBytes"] = needFiles, needBytes
|
res["needFiles"], res["needDeletes"], res["needBytes"] = needFiles, needDeletes, needBytes
|
||||||
|
|
||||||
res["inSyncFiles"], res["inSyncBytes"] = globalFiles-needFiles, globalBytes-needBytes
|
res["inSyncFiles"], res["inSyncBytes"] = globalFiles-needFiles, globalBytes-needBytes
|
||||||
|
|
||||||
|
@ -31,8 +31,8 @@ func (m *mockedModel) NeedFolderFiles(folder string, page, perpage int) ([]db.Fi
|
|||||||
return nil, nil, nil, 0
|
return nil, nil, nil, 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *mockedModel) NeedSize(folder string) (nfiles int, bytes int64) {
|
func (m *mockedModel) NeedSize(folder string) (nfiles, ndeletes int, bytes int64) {
|
||||||
return 0, 0
|
return 0, 0, 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *mockedModel) ConnectionStats() map[string]interface{} {
|
func (m *mockedModel) ConnectionStats() map[string]interface{} {
|
||||||
|
@ -564,7 +564,7 @@ func (m *Model) LocalSize(folder string) (nfiles, deleted int, bytes int64) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NeedSize returns the number and total size of currently needed files.
|
// NeedSize returns the number and total size of currently needed files.
|
||||||
func (m *Model) NeedSize(folder string) (nfiles int, bytes int64) {
|
func (m *Model) NeedSize(folder string) (nfiles, ndeletes int, bytes int64) {
|
||||||
m.fmut.RLock()
|
m.fmut.RLock()
|
||||||
defer m.fmut.RUnlock()
|
defer m.fmut.RUnlock()
|
||||||
if rf, ok := m.folderFiles[folder]; ok {
|
if rf, ok := m.folderFiles[folder]; ok {
|
||||||
@ -576,7 +576,8 @@ func (m *Model) NeedSize(folder string) (nfiles int, bytes int64) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fs, de, by := sizeOfFile(f)
|
fs, de, by := sizeOfFile(f)
|
||||||
nfiles += fs + de
|
nfiles += fs
|
||||||
|
ndeletes += de
|
||||||
bytes += by
|
bytes += by
|
||||||
return true
|
return true
|
||||||
})
|
})
|
||||||
|
@ -1720,6 +1720,17 @@ func TestIssue3496(t *testing.T) {
|
|||||||
t.Errorf("Fully complete, not possible: %.02f%%", comp.CompletionPct)
|
t.Errorf("Fully complete, not possible: %.02f%%", comp.CompletionPct)
|
||||||
}
|
}
|
||||||
t.Log(comp)
|
t.Log(comp)
|
||||||
|
|
||||||
|
// Check that NeedSize does the correct thing
|
||||||
|
files, deletes, bytes := m.NeedSize("default")
|
||||||
|
if files != 1 || bytes != 1234 {
|
||||||
|
// The one we added synthetically above
|
||||||
|
t.Errorf("Incorrect need size; %d, %d != 1, 1234", files, bytes)
|
||||||
|
}
|
||||||
|
if deletes != len(localFiles)-1 {
|
||||||
|
// The rest
|
||||||
|
t.Errorf("Incorrect need deletes; %d != %d", deletes, len(localFiles)-1)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func addFakeConn(m *Model, dev protocol.DeviceID) {
|
func addFakeConn(m *Model, dev protocol.DeviceID) {
|
||||||
|
Loading…
Reference in New Issue
Block a user