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