lib/db: Fix sequence updating for remote invalid items (#5420)
* lib/db: Fix sequence updating for remote invalid items * fix for the unit test introduced in the previous commit * lib/db: Polish blockmap
This commit is contained in:
@@ -107,16 +107,18 @@ func (m *metadataTracker) countsPtr(dev protocol.DeviceID, flags uint32) *Counts
|
||||
// addFile adds a file to the counts, adjusting the sequence number as
|
||||
// appropriate
|
||||
func (m *metadataTracker) addFile(dev protocol.DeviceID, f FileIntf) {
|
||||
if f.IsInvalid() && f.FileLocalFlags() == 0 {
|
||||
// This is a remote invalid file; it does not count.
|
||||
return
|
||||
}
|
||||
|
||||
m.mut.Lock()
|
||||
defer m.mut.Unlock()
|
||||
|
||||
m.dirty = true
|
||||
|
||||
m.updateSeqLocked(dev, f)
|
||||
|
||||
if f.IsInvalid() && f.FileLocalFlags() == 0 {
|
||||
// This is a remote invalid file; it does not count.
|
||||
return
|
||||
}
|
||||
|
||||
if flags := f.FileLocalFlags(); flags == 0 {
|
||||
// Account regular files in the zero-flags bucket.
|
||||
m.addFileLocked(dev, 0, f)
|
||||
@@ -128,6 +130,21 @@ func (m *metadataTracker) addFile(dev protocol.DeviceID, f FileIntf) {
|
||||
}
|
||||
}
|
||||
|
||||
func (m *metadataTracker) Sequence(dev protocol.DeviceID) int64 {
|
||||
m.mut.Lock()
|
||||
defer m.mut.Unlock()
|
||||
return m.countsPtr(dev, 0).Sequence
|
||||
}
|
||||
|
||||
func (m *metadataTracker) updateSeqLocked(dev protocol.DeviceID, f FileIntf) {
|
||||
if dev == protocol.GlobalDeviceID {
|
||||
return
|
||||
}
|
||||
if cp := m.countsPtr(dev, 0); f.SequenceNo() > cp.Sequence {
|
||||
cp.Sequence = f.SequenceNo()
|
||||
}
|
||||
}
|
||||
|
||||
func (m *metadataTracker) addFileLocked(dev protocol.DeviceID, flags uint32, f FileIntf) {
|
||||
cp := m.countsPtr(dev, flags)
|
||||
|
||||
@@ -142,10 +159,6 @@ func (m *metadataTracker) addFileLocked(dev protocol.DeviceID, flags uint32, f F
|
||||
cp.Files++
|
||||
}
|
||||
cp.Bytes += f.FileSize()
|
||||
|
||||
if seq := f.SequenceNo(); seq > cp.Sequence {
|
||||
cp.Sequence = seq
|
||||
}
|
||||
}
|
||||
|
||||
// removeFile removes a file from the counts
|
||||
|
||||
Reference in New Issue
Block a user