Skip to content

Commit

Permalink
check httpStatus200 before any session op
Browse files Browse the repository at this point in the history
  • Loading branch information
vbauerster committed Jul 24, 2024
1 parent 0a0d50e commit 0b459c7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 16 deletions.
14 changes: 10 additions & 4 deletions getparty.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,9 +238,12 @@ func (cmd *Cmd) Run(args []string, version, commit string) (err error) {
if err != nil {
return err
}
var httpStatus200 bool
sessionHandle := cmd.makeSessionHandler(session, progress)
defer func() {
sessionHandle(false)
if !httpStatus200 {
sessionHandle(false)
}
}()

var eg errgroup.Group
Expand Down Expand Up @@ -304,6 +307,7 @@ func (cmd *Cmd) Run(args []string, version, commit string) (err error) {
}
}
cancelTotalBar(true)
httpStatus200 = true
cmd.loggers[DEBUG].Printf("P%02d got http status 200", id)
case <-http200Ctx.Done():
}
Expand All @@ -316,9 +320,11 @@ func (cmd *Cmd) Run(args []string, version, commit string) (err error) {
return err
}

err = session.concatenateParts(progress)
if err != nil {
return err
if !httpStatus200 {
err = session.concatenateParts(progress)
if err != nil {
return err
}
}
if cmd.options.JSONFileName != "" {
return os.Remove(cmd.options.JSONFileName)
Expand Down
12 changes: 0 additions & 12 deletions session.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,22 +152,10 @@ func (s Session) checkSizeOfEachPart() error {
return nil
}

func (s Session) isHttpStatusOK() bool {
for _, p := range s.Parts {
if p.httpStatusOK {
return true
}
}
return false
}

func (s Session) concatenateParts(progress *mpb.Progress) (err error) {
if len(s.Parts) <= 1 {
return nil
}
if s.isHttpStatusOK() {
return errors.New("Cannot concatenate session with http status 200")
}
if tw := s.totalWritten(); tw != s.ContentLength {
return errors.Errorf("Written count mismatch: written=%d ContentLength=%d", tw, s.ContentLength)
}
Expand Down

0 comments on commit 0b459c7

Please sign in to comment.