Skip to content

Commit

Permalink
megacheck
Browse files Browse the repository at this point in the history
  • Loading branch information
tgulacsi committed Dec 13, 2017
1 parent 6a9386f commit 6b77592
Show file tree
Hide file tree
Showing 33 changed files with 110 additions and 150 deletions.
2 changes: 1 addition & 1 deletion converter/conclimit.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2013 The Agostle Authors. All rights reserved.
// Copyright 2017 The Agostle Authors. All rights reserved.
// Use of this source code is governed by an Apache 2.0
// license that can be found in the LICENSE file.

Expand Down
2 changes: 1 addition & 1 deletion converter/config.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2013 The Agostle Authors. All rights reserved.
// Copyright 2017 The Agostle Authors. All rights reserved.
// Use of this source code is governed by an Apache 2.0
// license that can be found in the LICENSE file.

Expand Down
4 changes: 2 additions & 2 deletions converter/converter.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2013 The Agostle Authors. All rights reserved.
// Copyright 2017 The Agostle Authors. All rights reserved.
// Use of this source code is governed by an Apache 2.0
// license that can be found in the LICENSE file.

Expand Down Expand Up @@ -225,7 +225,7 @@ func HTMLToPdf(ctx context.Context, destfn string, r io.Reader, contentType stri
}
}
buf.Reset()
if err := html.Render(&buf, img); err != nil {
if err = html.Render(&buf, img); err != nil {
Log("msg", "html.Render", "img", img, "error", err)
continue
}
Expand Down
2 changes: 1 addition & 1 deletion converter/converter_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2013 The Agostle Authors. All rights reserved.
// Copyright 2017 The Agostle Authors. All rights reserved.
// Use of this source code is governed by an Apache 2.0
// license that can be found in the LICENSE file.

Expand Down
2 changes: 1 addition & 1 deletion converter/decoders.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2013 The Agostle Authors. All rights reserved.
// Copyright 2017 The Agostle Authors. All rights reserved.
// Use of this source code is governed by an Apache 2.0
// license that can be found in the LICENSE file.

Expand Down
12 changes: 11 additions & 1 deletion converter/decoders_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2013 The Agostle Authors. All rights reserved.
// Copyright 2017 The Agostle Authors. All rights reserved.
// Use of this source code is governed by an Apache 2.0
// license that can be found in the LICENSE file.

Expand All @@ -10,6 +10,16 @@ import (
"testing"
)

func min(x ...int) int {
a := x[0]
for i := 1; i < len(x); i++ {
if a > x[i] {
a = x[i]
}
}
return a
}

var deBorkTests = [][2]string{
[2]string{"saddsgfgrv$#EWfedsv+dsfsadgfg", "saddsgfgrv$#EWfedsv+dsfsadgfg"},
[2]string{`+ADw-p class+AD0AIg-MsoNormal+ACI- align+AD0AIg-right+ACI- style+AD0AIg-tex=
Expand Down
2 changes: 1 addition & 1 deletion converter/fileutils.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2013 The Agostle Authors. All rights reserved.
// Copyright 2017 The Agostle Authors. All rights reserved.
// Use of this source code is governed by an Apache 2.0
// license that can be found in the LICENSE file.

Expand Down
58 changes: 23 additions & 35 deletions converter/filters.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2013 The Agostle Authors. All rights reserved.
// Copyright 2017 The Agostle Authors. All rights reserved.
// Use of this source code is governed by an Apache 2.0
// license that can be found in the LICENSE file.

Expand Down Expand Up @@ -69,9 +69,7 @@ func MailToSplittedPdfZip(ctx context.Context, destfn string, body io.Reader,
rch := make(chan maybeArchItems, len(files))
tbz := make([]ArchFileItem, 0, 2*len(files))
if !split && imgmime == "" {
for _, a := range files {
tbz = append(tbz, a)
}
tbz = append(tbz, files...)
} else {
fts := make([]string, len(files))
for i, a := range files {
Expand Down Expand Up @@ -284,15 +282,14 @@ func PdfToImageMulti(ctx context.Context, sfiles []string, imgmime, imgsize stri
work := func() {
defer ConcLimit.Release(ConcLimit.Acquire())
defer workWg.Done()
var err error
for args := range workch {
err = PdfToImage(ctx, args.w, args.r, args.mime, args.size)
if e := args.w.Close(); e != nil && err == nil {
err = e
imErr := PdfToImage(ctx, args.w, args.r, args.mime, args.size)
if e := args.w.Close(); e != nil && imErr == nil {
imErr = e
}
_ = args.r.Close()
if err != nil {
errch <- err
if imErr != nil {
errch <- imErr
} else {
imgfnsMtx.Lock()
imgfilenames = append(imgfilenames, args.name)
Expand Down Expand Up @@ -357,7 +354,6 @@ func SlurpMail(ctx context.Context, partch chan<- i18nmail.MailPart, errch chan<
if _, params, _ := mime.ParseMediaType(
mp.Header.Get("Content-Disposition"),
); params != nil {
var n int
s := params["size"]
if s != "" {
n, _ = strconv.Atoi(s)
Expand Down Expand Up @@ -424,7 +420,7 @@ func MailToPdfFiles(ctx context.Context, r io.Reader) (files []ArchFileItem, err

hshS := base64.URLEncoding.EncodeToString(hsh.Sum(nil))
ctx, _ = prepareContext(ctx, hshS)
if _, err := br.Seek(0, 0); err != nil {
if _, err = br.Seek(0, 0); err != nil {
return nil, err
}
r = br
Expand All @@ -444,7 +440,7 @@ func MailToPdfFiles(ctx context.Context, r io.Reader) (files []ArchFileItem, err
worker := func() {
defer workWg.Done()
for mp := range partch {
if err := convertPart(ctx, mp, resultch); err != nil {
if err = convertPart(ctx, mp, resultch); err != nil {
errch <- err
}
}
Expand Down Expand Up @@ -561,18 +557,18 @@ func MailToTree(ctx context.Context, outdir string, r io.Reader) error {
upr := make([]string, 4)

mpName := func(mp i18nmail.MailPart) string {
fn := mp.Header.Get("X-FileName")
if fn == "" {
fn = "eml"
xfn := mp.Header.Get("X-FileName")
if xfn == "" {
xfn = "eml"
}
return fmt.Sprintf("%03d.%s.%s", mp.Seq,
strings.Replace(mp.ContentType, "/", "--", -1), fn)
strings.Replace(mp.ContentType, "/", "--", -1), xfn)
}

if err = os.MkdirAll(outdir, 0750); err != nil {
return errors.Wrapf(err, "MailToTree(%q)", outdir)
}
partch := make(chan i18nmail.MailPart, 0)
partch := make(chan i18nmail.MailPart)
errch := make(chan error, 128)
go SlurpMail(ctx, partch, errch, r)

Expand Down Expand Up @@ -679,8 +675,9 @@ func ExtractingFilter(ctx context.Context,
)
body := part.Body
if part.ContentType == "application/x-ole-storage" {
r, err := NewOLEStorageReader(ctx, body)
if err != nil {
r, oleErr := NewOLEStorageReader(ctx, body)
if oleErr != nil {
err = oleErr
goto Error
}
child := part.Spawn()
Expand Down Expand Up @@ -711,15 +708,15 @@ func ExtractingFilter(ctx context.Context,
goto Error
}
for i, z := range zr.List() {
rc, err := z.Open()
if err != nil {
Log("msg", "open zip element", "i", i, "error", err)
rc, zErr := z.Open()
if zErr != nil {
Log("msg", "open zip element", "i", i, "error", zErr)
continue
}
chunk, err := ioutil.ReadAll(rc)
chunk, cErr := ioutil.ReadAll(rc)
_ = rc.Close()
if err != nil {
Log("msg", "read zip element", "i", i, "error", err)
if cErr != nil {
Log("msg", "read zip element", "i", i, "error", cErr)
continue
}
child := part.Spawn()
Expand All @@ -744,15 +741,6 @@ func ExtractingFilter(ctx context.Context,
}
}

func min(x ...int) int {
a := x[0]
for i := 1; i < len(x); i++ {
if a > x[i] {
a = x[i]
}
}
return a
}
func max(x ...int) int {
a := x[0]
for i := 1; i < len(x); i++ {
Expand Down
2 changes: 1 addition & 1 deletion converter/filters_header.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2013 The Agostle Authors. All rights reserved.
// Copyright 2017 The Agostle Authors. All rights reserved.
// Use of this source code is governed by an Apache 2.0
// license that can be found in the LICENSE file.

Expand Down
4 changes: 2 additions & 2 deletions converter/filters_html.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2013 The Agostle Authors. All rights reserved.
// Copyright 2017 The Agostle Authors. All rights reserved.
// Use of this source code is governed by an Apache 2.0
// license that can be found in the LICENSE file.

Expand Down Expand Up @@ -179,7 +179,7 @@ func HTMLPartFilter(ctx context.Context,
found := false
if len(groups) > 0 {
for act := &part; act != nil; act = act.Parent {
if _, ok := groups[act.Seq]; ok {
if _, ok = groups[act.Seq]; ok {
found = true
this = act.Seq
break
Expand Down
8 changes: 4 additions & 4 deletions converter/filters_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2013 The Agostle Authors. All rights reserved.
// Copyright 2017 The Agostle Authors. All rights reserved.
// Use of this source code is governed by an Apache 2.0
// license that can be found in the LICENSE file.

Expand Down Expand Up @@ -39,9 +39,9 @@ func TestFixXMLCharset(t *testing.T) {
`<?xml version="1.0" charset="utf-8" ?>` + want[22:],
`<?xml version="1.0" charset="iso-8859-2" ?><!DOCTYPE html><p>` + string([]rune{225}) + "</p></html>",
} {
ctx, cancel := context.WithTimeout(ctx, 10*time.Second)
b, err := ioutil.ReadAll(fixXMLCharset(ctx, strings.NewReader(elt)))
cancel()
subCtx, subCancel := context.WithTimeout(ctx, 10*time.Second)
b, err := ioutil.ReadAll(fixXMLCharset(subCtx, strings.NewReader(elt)))
subCancel()
if err != nil {
t.Errorf("%d. read: %v", i, err)
continue
Expand Down
2 changes: 1 addition & 1 deletion converter/filters_text.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2013 The Agostle Authors. All rights reserved.
// Copyright 2017 The Agostle Authors. All rights reserved.
// Use of this source code is governed by an Apache 2.0
// license that can be found in the LICENSE file.

Expand Down
16 changes: 3 additions & 13 deletions converter/image.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2013 The Agostle Authors. All rights reserved.
// Copyright 2017 The Agostle Authors. All rights reserved.
// Use of this source code is governed by an Apache 2.0
// license that can be found in the LICENSE file.

Expand All @@ -7,7 +7,6 @@ package converter
import (
"bytes"
"context"
"fmt"
"io"
"io/ioutil"
"os"
Expand Down Expand Up @@ -105,7 +104,7 @@ func PdfToImageCairo(ctx context.Context, w io.Writer, r io.Reader, contentType,
cmd.Stdin = r
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
if err := cmd.Run(); err != nil {
if err = cmd.Run(); err != nil {
return errors.Wrapf(err, "%q", cmd.Args)
}
if tfh, err = os.Open(fn); err != nil {
Expand Down Expand Up @@ -151,7 +150,7 @@ func PdfToImageGm(ctx context.Context, w io.Writer, r io.Reader, contentType, si
//cmd.Stdout = &filterFirstLines{Beginning: []string{"Can't find ", "Warning: "}, Writer: w}
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
if err := cmd.Run(); err != nil {
if err = cmd.Run(); err != nil {
return errors.Wrapf(err, "%q", cmd.Args)
}
fn := tfh.Name()
Expand All @@ -166,12 +165,3 @@ func PdfToImageGm(ctx context.Context, w io.Writer, r io.Reader, contentType, si
_ = os.Remove(fn)
return err
}

func fitImageFile(ctx context.Context, dst, src string, width, height int) error {
cmd := command(ctx, *ConfGm, "convert", src, "-density", "300", "-resize", fmt.Sprintf("%dx%d", width, height), dst)
cmd.Stdout, cmd.Stderr = os.Stdout, os.Stderr
if err := cmd.Run(); err != nil {
return errors.Wrapf(err, "%q", cmd.Args)
}
return nil
}
2 changes: 1 addition & 1 deletion converter/image_pdfdirect.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// +build pdfdirect

// Copyright 2013 The Agostle Authors. All rights reserved.
// Copyright 2017 The Agostle Authors. All rights reserved.
// Use of this source code is governed by an Apache 2.0
// license that can be found in the LICENSE file.

Expand Down
2 changes: 1 addition & 1 deletion converter/mail_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2013 The Agostle Authors. All rights reserved.
// Copyright 2017 The Agostle Authors. All rights reserved.
// Use of this source code is governed by an Apache 2.0
// license that can be found in the LICENSE file.

Expand Down
4 changes: 2 additions & 2 deletions converter/outlook.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2013 The Agostle Authors. All rights reserved.
// Copyright 2017 The Agostle Authors. All rights reserved.
// Use of this source code is governed by an Apache 2.0
// license that can be found in the LICENSE file.

Expand Down Expand Up @@ -101,7 +101,7 @@ func newOLEStorageReaderDirect(ctx context.Context, r io.Reader) (io.ReadCloser,
cmd.Stdout = pw
cmd.Stderr = &errBuf
Log("msg", "OLEStorageReader", "args", cmd.Args)
if err := cmd.Start(); err != nil {
if err = cmd.Start(); err != nil {
return nil, errors.Wrapf(err, "OLEStorageReader: %s", errBuf.String())
}
go func() {
Expand Down
Loading

0 comments on commit 6b77592

Please sign in to comment.