Skip to content

Commit

Permalink
booster cat: return an error if the requested file doesn't exist
Browse files Browse the repository at this point in the history
Presently, it is not possible to distinguish between an empty file
and a non-existent file based on the `booster cat` output and exit
status. With this patch applied, booster prints an error message to
standard error and exists with a non-zero exit status if the file
was not found in the image.
  • Loading branch information
nmeum authored and anatol committed Mar 14, 2023
1 parent e867f92 commit ab0f6f3
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion generator/unpack.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"compress/gzip"
"fmt"
"io"
"io/fs"
"os"
"path/filepath"

Expand Down Expand Up @@ -133,16 +134,27 @@ func runUnpack() error {
}

func runCat() error {
var foundFile bool
fn := func(hdr *cpio.Header, r *cpio.Reader) error {
if hdr.Name == opts.CatCommand.Args.File {
if _, err := io.Copy(os.Stdout, r); err != nil {
return err
}

foundFile = true
return errStop
}
return nil
}
return processImage(opts.CatCommand.Args.Image, fn)

err := processImage(opts.CatCommand.Args.Image, fn)
if err != nil {
return err
} else if !foundFile {
return fs.ErrNotExist
}

return nil
}

func runLs() error {
Expand Down

0 comments on commit ab0f6f3

Please sign in to comment.