undocker

extract docker archives
Log | Files | Refs | README | LICENSE

commit e6d1a95c02daffd2c09f677fe92df84bbda0a018 (tree)
parent 725fb5679bc96072107da15a2e8ba938ad2760eb
Author: Motiejus Jakštys <motiejus@uber.com>
Date:   Fri, 19 May 2023 15:01:44 +0300

upgrade to go 1.20

use errors.Join

Diffstat:
Mgo.mod | 2+-
Mmain.go | 11++++-------
Mrootfs/rootfs.go | 6+-----
3 files changed, 6 insertions(+), 13 deletions(-)

diff --git a/go.mod b/go.mod @@ -1,3 +1,3 @@ module git.jakstys.lt/motiejus/undocker -go 1.16 +go 1.20 diff --git a/main.go b/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 diff --git a/rootfs/rootfs.go b/rootfs/rootfs.go @@ -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 {