fix: report errors correctly when pulling, fix EEXIST

Kaniko adds an entry for the root folder `/` in its tarballs.
Processing the file causes the process to hang when trying to
recreate the destination directory.

The root directory already exists, so it triggers an error, but as the
errors were not correctly propagated, the process hangs forever.

Fix both issues.

Signed-off-by: Andrey Smirnov <andrey.smirnov@siderolabs.com>
This commit is contained in:
Matthieu Mottet 2024-08-29 12:56:26 +02:00 committed by Andrey Smirnov
parent b309e87b40
commit 81f9fcd9ce
No known key found for this signature in database
GPG Key ID: FE042E3D4085A811
2 changed files with 17 additions and 5 deletions

View File

@ -47,10 +47,10 @@ func Untar(ctx context.Context, r io.Reader, rootPath string) error {
switch hdr.Typeflag {
case tar.TypeDir:
mode := hdr.FileInfo().Mode()
mode := hdr.FileInfo().Mode() & os.ModePerm
mode |= 0o700 // make rwx for the owner
if err = os.Mkdir(path, mode); err != nil {
if err = os.Mkdir(path, mode); err != nil && !os.IsExist(err) {
return fmt.Errorf("error creating directory %q mode %s: %w", path, mode, err)
}

View File

@ -353,13 +353,25 @@ func (c *ContainerAsset) Extract(ctx context.Context, destination, arch string,
eg, ctx := errgroup.WithContext(ctx)
eg.Go(func() error {
defer w.Close() //nolint:errcheck
if exportErr := crane.Export(img, w); exportErr != nil {
w.CloseWithError(exportErr)
return crane.Export(img, w)
return exportErr
}
w.Close() //nolint:errcheck
return nil
})
eg.Go(func() error {
return archiver.Untar(ctx, r, destination)
if untarErr := archiver.Untar(ctx, r, destination); untarErr != nil {
r.CloseWithError(untarErr)
return untarErr
}
return nil
})
return eg.Wait()