1
0
Эх сурвалжийг харах

WIP: Consider tempfile when checking for free space (fixes #2598)

Checks the existing blocks that can be reused when downloading a file so
that it only requires the space corresponding to the missing blocks.
This will prevent syncthing from claiming the folder doesn't have enough
space when resuming download of large files after they have been
partially downloaded.
Anderson Mesquita 10 жил өмнө
parent
commit
3f94e70488
1 өөрчлөгдсөн 18 нэмэгдсэн , 15 устгасан
  1. 18 15
      lib/model/rwfolder.go

+ 18 - 15
lib/model/rwfolder.go

@@ -969,25 +969,11 @@ func (p *rwFolder) handleFile(file protocol.FileInfo, copyChan chan<- copyBlocks
 		}
 		}
 	}
 	}
 
 
-	if p.checkFreeSpace {
-		if free, err := osutil.DiskFreeBytes(p.dir); err == nil && free < file.Size() {
-			l.Warnf(`Folder "%s": insufficient disk space in %s for %s: have %.2f MiB, need %.2f MiB`, p.folder, p.dir, file.Name, float64(free)/1024/1024, float64(file.Size())/1024/1024)
-			p.newError(file.Name, errors.New("insufficient space"))
-			return
-		}
-	}
-
-	events.Default.Log(events.ItemStarted, map[string]string{
-		"folder": p.folder,
-		"item":   file.Name,
-		"type":   "file",
-		"action": "update",
-	})
-
 	scanner.PopulateOffsets(file.Blocks)
 	scanner.PopulateOffsets(file.Blocks)
 
 
 	reused := 0
 	reused := 0
 	var blocks []protocol.BlockInfo
 	var blocks []protocol.BlockInfo
+	var blocksSize int64
 
 
 	// Check for an old temporary file which might have some blocks we could
 	// Check for an old temporary file which might have some blocks we could
 	// reuse.
 	// reuse.
@@ -1007,6 +993,7 @@ func (p *rwFolder) handleFile(file protocol.FileInfo, copyChan chan<- copyBlocks
 			_, ok := existingBlocks[block.String()]
 			_, ok := existingBlocks[block.String()]
 			if !ok {
 			if !ok {
 				blocks = append(blocks, block)
 				blocks = append(blocks, block)
+				blocksSize += int64(block.Size)
 			}
 			}
 		}
 		}
 
 
@@ -1021,8 +1008,24 @@ func (p *rwFolder) handleFile(file protocol.FileInfo, copyChan chan<- copyBlocks
 		}
 		}
 	} else {
 	} else {
 		blocks = file.Blocks
 		blocks = file.Blocks
+		blocksSize = file.Size()
 	}
 	}
 
 
+	if p.checkFreeSpace {
+		if free, err := osutil.DiskFreeBytes(p.dir); err == nil && free < blocksSize {
+			l.Warnf(`Folder "%s": insufficient disk space in %s for %s: have %.2f MiB, need %.2f MiB`, p.folder, p.dir, file.Name, float64(free)/1024/1024, float64(blocksSize)/1024/1024)
+			p.newError(file.Name, errors.New("insufficient space"))
+			return
+		}
+	}
+
+	events.Default.Log(events.ItemStarted, map[string]string{
+		"folder": p.folder,
+		"item":   file.Name,
+		"type":   "file",
+		"action": "update",
+	})
+
 	s := sharedPullerState{
 	s := sharedPullerState{
 		file:        file,
 		file:        file,
 		folder:      p.folder,
 		folder:      p.folder,