Skip to content

Commit

Permalink
Allows companion overlaps to exist for file to be "complete"
Browse files Browse the repository at this point in the history
  • Loading branch information
sbeus committed Mar 2, 2024
1 parent 9f78abb commit 21ea68c
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions stage/companion.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,27 @@ func companionPartExists(cmp *sts.Partial, beg, end int64) bool {
}

func isCompanionComplete(cmp *sts.Partial) bool {
size := int64(0)
for _, part := range cmp.Parts {
size += part.End - part.Beg
// Sometimes the companion ends up with overlapping parts but the file is intact. As
// long as there are no gaps, it starts at zero, and ends at the file size, we
// consider it complete and then if the hash doesn't happen to match, the file will
// be sent again.
if len(cmp.Parts) == 0 {
return false
}
if len(cmp.Parts) == 1 {
return cmp.Parts[0].Beg == 0 && cmp.Parts[0].End == cmp.Size
}
pf := cmp.Parts[0]
pl := cmp.Parts[len(cmp.Parts)-1]
if pf.Beg != 0 || pl.End != cmp.Size {
return false
}
for i, part := range cmp.Parts[1:] {
if part.Beg > cmp.Parts[i].End {
return false
}
}
return size == cmp.Size
return true
}

type oldCompanion struct {
Expand Down

0 comments on commit 21ea68c

Please sign in to comment.