1 Commits

Author SHA1 Message Date
Motiejus Jakštys
e6d1a95c02 upgrade to go 1.20
use errors.Join
2023-05-19 15:05:21 +03:00
3 changed files with 6 additions and 13 deletions

2
go.mod
View File

@@ -1,3 +1,3 @@
module git.jakstys.lt/motiejus/undocker
go 1.16
go 1.20

11
main.go
View File

@@ -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

View File

@@ -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 {