lib/db: Use flags from arg not LocalFlags() updating meta (#6333)

This commit is contained in:
Simon Frei
2020-02-13 14:02:30 +01:00
committed by GitHub
parent 51fa36d61f
commit ca90f4e6af
+13 -9
View File
@@ -28,8 +28,8 @@ type metadataTracker struct {
} }
type metaKey struct { type metaKey struct {
dev protocol.DeviceID dev protocol.DeviceID
flags uint32 flag uint32
} }
func newMetadataTracker() *metadataTracker { func newMetadataTracker() *metadataTracker {
@@ -103,14 +103,18 @@ func (m *metadataTracker) fromDB(db *Lowlevel, folder []byte) error {
// countsPtr returns a pointer to the corresponding Counts struct, if // countsPtr returns a pointer to the corresponding Counts struct, if
// necessary allocating one in the process // necessary allocating one in the process
func (m *metadataTracker) countsPtr(dev protocol.DeviceID, flags uint32) *Counts { func (m *metadataTracker) countsPtr(dev protocol.DeviceID, flag uint32) *Counts {
// must be called with the mutex held // must be called with the mutex held
key := metaKey{dev, flags} if bits.OnesCount32(flag) > 1 {
panic("incorrect usage: set at most one bit in flag")
}
key := metaKey{dev, flag}
idx, ok := m.indexes[key] idx, ok := m.indexes[key]
if !ok { if !ok {
idx = len(m.counts.Counts) idx = len(m.counts.Counts)
m.counts.Counts = append(m.counts.Counts, Counts{DeviceID: dev[:], LocalFlags: flags}) m.counts.Counts = append(m.counts.Counts, Counts{DeviceID: dev[:], LocalFlags: flag})
m.indexes[key] = idx m.indexes[key] = idx
} }
return &m.counts.Counts[idx] return &m.counts.Counts[idx]
@@ -157,8 +161,8 @@ func (m *metadataTracker) updateSeqLocked(dev protocol.DeviceID, f FileIntf) {
} }
} }
func (m *metadataTracker) addFileLocked(dev protocol.DeviceID, flags uint32, f FileIntf) { func (m *metadataTracker) addFileLocked(dev protocol.DeviceID, flag uint32, f FileIntf) {
cp := m.countsPtr(dev, flags) cp := m.countsPtr(dev, flag)
switch { switch {
case f.IsDeleted(): case f.IsDeleted():
@@ -196,8 +200,8 @@ func (m *metadataTracker) removeFile(dev protocol.DeviceID, f FileIntf) {
} }
} }
func (m *metadataTracker) removeFileLocked(dev protocol.DeviceID, flags uint32, f FileIntf) { func (m *metadataTracker) removeFileLocked(dev protocol.DeviceID, flag uint32, f FileIntf) {
cp := m.countsPtr(dev, f.FileLocalFlags()) cp := m.countsPtr(dev, flag)
switch { switch {
case f.IsDeleted(): case f.IsDeleted():