Browse Source

Slightly more conservative guess on file size

Jakob Borg 11 years ago
parent
commit
ad273adb78
1 changed files with 6 additions and 2 deletions
  1. 6 2
      protocol/message.go

+ 6 - 2
protocol/message.go

@@ -49,12 +49,16 @@ type FileInfoTruncated struct {
 	NumBlocks    uint32
 }
 
-// Returns an upper bound on the size, not the exact figure
+// Returns a statistical guess on the size, not the exact figure
 func (f FileInfoTruncated) Size() int64 {
 	if IsDeleted(f.Flags) || IsDirectory(f.Flags) {
 		return 128
 	}
-	return int64(f.NumBlocks) * BlockSize
+	if f.NumBlocks < 2 {
+		return BlockSize / 2
+	} else {
+		return int64(f.NumBlocks-1)*BlockSize + BlockSize/2
+	}
 }
 
 func (f FileInfoTruncated) IsDeleted() bool {