diff options
author | Jakob Borg <jakob@kastelo.net> | 2018-02-14 11:25:34 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-02-14 11:25:34 +0100 |
commit | 7a92f6c6b18230f74cc347f937fe81b44da6c9ee (patch) | |
tree | 9cb3855ad8bede3e4a34e27a6197d6133f584244 | |
parent | 68c1b2dd472f18c3c37bb188fdb106df55dea927 (diff) | |
download | syncthing-7a92f6c6b18230f74cc347f937fe81b44da6c9ee.tar.gz syncthing-7a92f6c6b18230f74cc347f937fe81b44da6c9ee.zip |
lib/db: Don't panic on negative counts (#4761)v0.14.45-rc.3v0.14.45
* lib/db: Don't panic on negative counts (fixes #4659)
So, negative counts should never happen and hence the original idea to
panic. However, this sucks as the panic will happen in a folder runner,
be automatically swallowed by suture, and the runner gets restarted but
now we are in a bad state. (Related: #4758)
At the time of writing the global list is somewhat in flux (we've
changed how ignored files are handled, invalid bits, etc.) and I think
that can cause unusual conditions here. Hence just fixing up the numbers
instead until the next full recount.
-rw-r--r-- | lib/db/meta.go | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/lib/db/meta.go b/lib/db/meta.go index 4a2504c44..09015b174 100644 --- a/lib/db/meta.go +++ b/lib/db/meta.go @@ -134,8 +134,24 @@ func (m *metadataTracker) removeFile(dev protocol.DeviceID, f FileIntf) { } cp.Bytes -= f.FileSize() - if cp.Deleted < 0 || cp.Files < 0 || cp.Directories < 0 || cp.Symlinks < 0 { - panic("bug: removed more than added") + // If we've run into an impossible situation, correct it for now and set + // the created timestamp to zero. Next time we start up the metadata + // will be seen as infinitely old and recalculated from scratch. + if cp.Deleted < 0 { + cp.Deleted = 0 + m.counts.Created = 0 + } + if cp.Files < 0 { + cp.Files = 0 + m.counts.Created = 0 + } + if cp.Directories < 0 { + cp.Directories = 0 + m.counts.Created = 0 + } + if cp.Symlinks < 0 { + cp.Symlinks = 0 + m.counts.Created = 0 } m.mut.Unlock() |