Browse Source

lib/model: Handle invalid needed items on send-only (ref #7476) (#7596)

Simon Frei 4 years ago
parent
commit
ec86db176e
1 changed files with 14 additions and 17 deletions
  1. 14 17
      lib/model/folder_sendonly.go

+ 14 - 17
lib/model/folder_sendonly.go

@@ -37,8 +37,10 @@ func (f *sendOnlyFolder) PullErrors() []FileError {
 
 
 // pull checks need for files that only differ by metadata (no changes on disk)
 // pull checks need for files that only differ by metadata (no changes on disk)
 func (f *sendOnlyFolder) pull() (bool, error) {
 func (f *sendOnlyFolder) pull() (bool, error) {
-	batch := make([]protocol.FileInfo, 0, maxBatchSizeFiles)
-	batchSizeBytes := 0
+	batch := newFileInfoBatch(func(files []protocol.FileInfo) error {
+		f.updateLocalsFromPulling(files)
+		return nil
+	})
 
 
 	snap, err := f.dbSnapshot()
 	snap, err := f.dbSnapshot()
 	if err != nil {
 	if err != nil {
@@ -46,45 +48,40 @@ func (f *sendOnlyFolder) pull() (bool, error) {
 	}
 	}
 	defer snap.Release()
 	defer snap.Release()
 	snap.WithNeed(protocol.LocalDeviceID, func(intf protocol.FileIntf) bool {
 	snap.WithNeed(protocol.LocalDeviceID, func(intf protocol.FileIntf) bool {
-		if len(batch) == maxBatchSizeFiles || batchSizeBytes > maxBatchSizeBytes {
-			f.updateLocalsFromPulling(batch)
-			batch = batch[:0]
-			batchSizeBytes = 0
-		}
+		batch.flushIfFull()
+
+		file := intf.(protocol.FileInfo)
 
 
 		if f.ignores.ShouldIgnore(intf.FileName()) {
 		if f.ignores.ShouldIgnore(intf.FileName()) {
-			file := intf.(protocol.FileInfo)
 			file.SetIgnored()
 			file.SetIgnored()
-			batch = append(batch, file)
-			batchSizeBytes += file.ProtoSize()
+			batch.append(file)
 			l.Debugln(f, "Handling ignored file", file)
 			l.Debugln(f, "Handling ignored file", file)
 			return true
 			return true
 		}
 		}
 
 
 		curFile, ok := snap.Get(protocol.LocalDeviceID, intf.FileName())
 		curFile, ok := snap.Get(protocol.LocalDeviceID, intf.FileName())
 		if !ok {
 		if !ok {
-			if intf.IsDeleted() {
+			if intf.IsInvalid() {
+				// Global invalid file just exists for need accounting
+				batch.append(file)
+			} else if intf.IsDeleted() {
 				l.Debugln("Should never get a deleted file as needed when we don't have it")
 				l.Debugln("Should never get a deleted file as needed when we don't have it")
 				f.evLogger.Log(events.Failure, "got deleted file that doesn't exist locally as needed when pulling on send-only")
 				f.evLogger.Log(events.Failure, "got deleted file that doesn't exist locally as needed when pulling on send-only")
 			}
 			}
 			return true
 			return true
 		}
 		}
 
 
-		file := intf.(protocol.FileInfo)
 		if !file.IsEquivalentOptional(curFile, f.modTimeWindow, f.IgnorePerms, false, 0) {
 		if !file.IsEquivalentOptional(curFile, f.modTimeWindow, f.IgnorePerms, false, 0) {
 			return true
 			return true
 		}
 		}
 
 
-		batch = append(batch, file)
-		batchSizeBytes += file.ProtoSize()
+		batch.append(file)
 		l.Debugln(f, "Merging versions of identical file", file)
 		l.Debugln(f, "Merging versions of identical file", file)
 
 
 		return true
 		return true
 	})
 	})
 
 
-	if len(batch) > 0 {
-		f.updateLocalsFromPulling(batch)
-	}
+	batch.flush()
 
 
 	return true, nil
 	return true, nil
 }
 }