images: double-check djpeg's failure with process state, to avoid false

alarm

http://camlistore.org/issue/550

Also fix confusing error msg

Change-Id: I68dd3c5a11f5b32028d21c006d73c55da950a58c
This commit is contained in:
mpl 2014-11-22 01:42:03 +01:00
parent 21a61dad40
commit 009e63ea77
2 changed files with 7 additions and 4 deletions

View File

@ -196,9 +196,12 @@ func DecodeDownsample(r io.Reader, factor int) (image.Image, error) {
stderrW := new(bytes.Buffer)
cmd.Stderr = stderrW
if err = cmd.Run(); err != nil {
djpegFailureVar.Add(1)
return nil, DjpegFailedError{Err: fmt.Errorf("%v: %s", err, stderrW)}
if err := cmd.Run(); err != nil {
if !cmd.ProcessState.Success() {
djpegFailureVar.Add(1)
return nil, DjpegFailedError{Err: fmt.Errorf("%v: %s", err, stderrW)}
}
// false alarm, so proceed. See http://camlistore.org/issue/550
}
djpegSuccessVar.Add(1)
djpegBytesReadVar.Add(int64(w.Len()))

View File

@ -432,7 +432,7 @@ func decode(r io.Reader, opts *DecodeOpts, swapDimensions bool) (im image.Image,
im, err = fastjpeg.DecodeDownsample(tr, factor)
switch err.(type) {
case fastjpeg.DjpegFailedError:
log.Printf("djpeg failed, retrying with jpeg.Decode: %v", err)
log.Printf("Retrying with jpeg.Decode, because djpeg failed with: %v", err)
im, err = jpeg.Decode(io.MultiReader(&buf, mr))
case nil:
// fallthrough to rescale() below.