blockDiff returns lists of common and missing (to transform src into tgt) blocks. Both block lists must have been created with the same block size.
(src, tgt []protocol.BlockInfo)
| 1213 | // blockDiff returns lists of common and missing (to transform src into tgt) |
| 1214 | // blocks. Both block lists must have been created with the same block size. |
| 1215 | func blockDiff(src, tgt []protocol.BlockInfo) ([]protocol.BlockInfo, []protocol.BlockInfo) { |
| 1216 | if len(tgt) == 0 { |
| 1217 | return nil, nil |
| 1218 | } |
| 1219 | |
| 1220 | if len(src) == 0 { |
| 1221 | // Copy the entire file |
| 1222 | return nil, tgt |
| 1223 | } |
| 1224 | |
| 1225 | have := make([]protocol.BlockInfo, 0, len(src)) |
| 1226 | need := make([]protocol.BlockInfo, 0, len(tgt)) |
| 1227 | |
| 1228 | for i := range tgt { |
| 1229 | if i >= len(src) { |
| 1230 | return have, append(need, tgt[i:]...) |
| 1231 | } |
| 1232 | if !bytes.Equal(tgt[i].Hash, src[i].Hash) { |
| 1233 | // Copy differing block |
| 1234 | need = append(need, tgt[i]) |
| 1235 | } else { |
| 1236 | have = append(have, tgt[i]) |
| 1237 | } |
| 1238 | } |
| 1239 | |
| 1240 | return have, need |
| 1241 | } |
| 1242 | |
| 1243 | // populateOffsets sets the Offset field on each block |
| 1244 | func populateOffsets(blocks []protocol.BlockInfo) { |