Browse Source

cmd/stindex, lib/db: Use same condition to check for needed files (#6954)

Simon Frei 5 years ago
parent
commit
0e3e0a7c9e
2 changed files with 17 additions and 17 deletions
  1. 5 5
      cmd/stindex/idxck.go
  2. 12 12
      lib/db/transactions.go

+ 5 - 5
cmd/stindex/idxck.go

@@ -333,10 +333,10 @@ func idxck(ldb backend.Backend) (success bool) {
 }
 
 func needsLocally(vl db.VersionList) bool {
-	fv, ok := vl.Get(protocol.LocalDeviceID[:])
-	if !ok {
-		return true // proviosinally, it looks like we need the file
+	gfv, gok := vl.GetGlobal()
+	if !gok { // That's weird, but we hardly need something non-existant
+		return false
 	}
-	gfv, _ := vl.GetGlobal() // Can't not have a global if we got something above
-	return !fv.Version.GreaterEqual(gfv.Version)
+	fv, ok := vl.Get(protocol.LocalDeviceID[:])
+	return db.Need(gfv, ok, fv.Version)
 }

+ 12 - 12
lib/db/transactions.go

@@ -457,7 +457,7 @@ func (t *readOnlyTransaction) withNeed(folder, device []byte, truncate bool, fn
 		}
 		haveFV, have := vl.Get(device)
 
-		if !need(globalFV, have, haveFV.Version) {
+		if !Need(globalFV, have, haveFV.Version) {
 			continue
 		}
 
@@ -630,9 +630,9 @@ func (t readWriteTransaction) updateGlobal(gk, keyBuf, folder, device []byte, fi
 
 	needBefore := false
 	if haveOldGlobal {
-		needBefore = need(oldGlobalFV, haveRemoved, removedFV.Version)
+		needBefore = Need(oldGlobalFV, haveRemoved, removedFV.Version)
 	}
-	needNow := need(globalFV, true, file.Version)
+	needNow := Need(globalFV, true, file.Version)
 	if needBefore {
 		if keyBuf, oldGlobal, err = t.getGlobalFromFileVersion(keyBuf, folder, name, true, oldGlobalFV); err != nil {
 			return nil, false, err
@@ -692,9 +692,9 @@ func (t readWriteTransaction) updateGlobal(gk, keyBuf, folder, device []byte, fi
 		localFV, haveLocal := fl.Get(protocol.LocalDeviceID[:])
 		needBefore := false
 		if haveOldGlobal {
-			needBefore = need(oldGlobalFV, haveLocal, localFV.Version)
+			needBefore = Need(oldGlobalFV, haveLocal, localFV.Version)
 		}
-		needNow := need(globalFV, haveLocal, localFV.Version)
+		needNow := Need(globalFV, haveLocal, localFV.Version)
 		if needBefore {
 			meta.removeNeeded(protocol.LocalDeviceID, oldGlobal)
 			if !needNow {
@@ -703,7 +703,7 @@ func (t readWriteTransaction) updateGlobal(gk, keyBuf, folder, device []byte, fi
 				}
 			}
 		}
-		if need(globalFV, haveLocal, localFV.Version) {
+		if Need(globalFV, haveLocal, localFV.Version) {
 			meta.addNeeded(protocol.LocalDeviceID, global)
 			if !needBefore {
 				if keyBuf, err = t.updateLocalNeed(keyBuf, folder, name, true); err != nil {
@@ -719,10 +719,10 @@ func (t readWriteTransaction) updateGlobal(gk, keyBuf, folder, device []byte, fi
 			continue
 		}
 		fv, have := fl.Get(dev[:])
-		if haveOldGlobal && need(oldGlobalFV, have, fv.Version) {
+		if haveOldGlobal && Need(oldGlobalFV, have, fv.Version) {
 			meta.removeNeeded(dev, oldGlobal)
 		}
-		if need(globalFV, have, fv.Version) {
+		if Need(globalFV, have, fv.Version) {
 			meta.addNeeded(dev, global)
 		}
 	}
@@ -754,7 +754,7 @@ func (t readWriteTransaction) updateLocalNeed(keyBuf, folder, name []byte, add b
 	return keyBuf, err
 }
 
-func need(global FileVersion, haveLocal bool, localVersion protocol.Vector) bool {
+func Need(global FileVersion, haveLocal bool, localVersion protocol.Vector) bool {
 	// We never need an invalid file.
 	if global.IsInvalid() {
 		return false
@@ -811,7 +811,7 @@ func (t readWriteTransaction) removeFromGlobal(gk, keyBuf, folder, device, file
 
 	globalFV, ok := fl.GetGlobal()
 	// Add potential needs of the removed device
-	if ok && !globalFV.IsInvalid() && need(globalFV, false, protocol.Vector{}) && !need(oldGlobalFV, haveRemoved, removedFV.Version) {
+	if ok && !globalFV.IsInvalid() && Need(globalFV, false, protocol.Vector{}) && !Need(oldGlobalFV, haveRemoved, removedFV.Version) {
 		keyBuf, global, _, err = t.getGlobalFromVersionList(keyBuf, folder, file, true, fl)
 		if err != nil {
 			return nil, err
@@ -842,7 +842,7 @@ func (t readWriteTransaction) removeFromGlobal(gk, keyBuf, folder, device, file
 	meta.removeFile(protocol.GlobalDeviceID, f)
 
 	// Remove potential device needs
-	if fv, have := fl.Get(protocol.LocalDeviceID[:]); need(removedFV, have, fv.Version) {
+	if fv, have := fl.Get(protocol.LocalDeviceID[:]); Need(removedFV, have, fv.Version) {
 		meta.removeNeeded(protocol.LocalDeviceID, f)
 		if keyBuf, err = t.updateLocalNeed(keyBuf, folder, file, false); err != nil {
 			return nil, err
@@ -852,7 +852,7 @@ func (t readWriteTransaction) removeFromGlobal(gk, keyBuf, folder, device, file
 		if bytes.Equal(dev[:], device) { // Was the previous global
 			continue
 		}
-		if fv, have := fl.Get(dev[:]); need(removedFV, have, fv.Version) {
+		if fv, have := fl.Get(dev[:]); Need(removedFV, have, fv.Version) {
 			meta.removeNeeded(deviceID, f)
 		}
 	}