upgrade to go 1.20
use errors.Join
This commit is contained in:
parent
725fb5679b
commit
e6d1a95c02
11
main.go
11
main.go
@ -2,6 +2,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
@ -59,10 +60,7 @@ func (c *command) execute(infile string, outfile string) (_err error) {
|
||||
return err
|
||||
}
|
||||
defer func() {
|
||||
err := rd.Close()
|
||||
if _err == nil {
|
||||
_err = err
|
||||
}
|
||||
_err = errors.Join(_err, rd.Close())
|
||||
}()
|
||||
|
||||
var out io.Writer
|
||||
@ -74,11 +72,10 @@ func (c *command) execute(infile string, outfile string) (_err error) {
|
||||
return fmt.Errorf("create: %w", err)
|
||||
}
|
||||
defer func() {
|
||||
err := outf.Close()
|
||||
if _err != nil {
|
||||
os.Remove(outfile)
|
||||
_err = errors.Join(_err, os.Remove(outfile))
|
||||
} else {
|
||||
_err = err
|
||||
_err = errors.Join(_err, outf.Close())
|
||||
}
|
||||
}()
|
||||
out = outf
|
||||
|
@ -144,11 +144,7 @@ func Flatten(rd io.ReadSeeker, w io.Writer) (_err error) {
|
||||
|
||||
tw := tar.NewWriter(w)
|
||||
defer func() {
|
||||
// Avoiding use of multierr: if error is present, return
|
||||
// that. Otherwise return whatever `Close` returns.
|
||||
if err := tw.Close(); err != nil && _err == nil {
|
||||
_err = err
|
||||
}
|
||||
_err = errors.Join(_err, tw.Close())
|
||||
}()
|
||||
// iterate through all layers, all files, and write files.
|
||||
for i, no := range layers {
|
||||
|
Loading…
Reference in New Issue
Block a user