Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions storage/pkg/chrootarchive/archive_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"io"
"io/fs"
"os"
"os/exec"
"path/filepath"
"runtime"
"strings"
Expand Down Expand Up @@ -82,6 +83,10 @@ func untar() {
}

if err := archive.Unpack(os.Stdin, dst, &options); err != nil {
if errors.Is(err, unix.ENOSPC) {
fmt.Fprint(os.Stderr, err)
os.Exit(int(unix.ENOSPC))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing guarantees that ENOSPC fits into the exit code.

}
fatal(err)
}
// fully consume stdin in case it is zero padded
Expand Down Expand Up @@ -155,6 +160,20 @@ func invokeUnpack(decompressedArchive io.Reader, dest *unpackDestination, option
w.Close()

if err := cmd.Wait(); err != nil {
if exitErr, ok := err.(*exec.ExitError); ok {
exitCode := exitErr.ExitCode()
if exitCode == int(unix.ENOSPC) {
procPath := fmt.Sprintf("/proc/self/fd/%d", dest.root.Fd())

path, err := os.Readlink(procPath)
Comment on lines +166 to +168
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why?

  • It’s not clear we need this
  • If we do, ultimately the public-API caller provides us with a path, we don’t have to reconstruct it.


if err == nil {
fmt.Fprintf(os.Stderr, "no space left on device: %s\n", path)
os.Exit(28)
Comment on lines +171 to +172
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A library code can’t very well just write to stderr and terminate the whole process!

}
}
}

errorOut := fmt.Errorf("unpacking failed (error: %w; output: %s)", err, output)
// when `xz -d -c -q | storage-untar ...` failed on storage-untar side,
// we need to exhaust `xz`'s output, otherwise the `xz` side will be
Expand Down