From ab0f6f3debdd1a0455cb37f71e782fbb244fc32a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6ren=20Tempel?= Date: Fri, 10 Mar 2023 15:57:00 +0100 Subject: [PATCH] booster cat: return an error if the requested file doesn't exist 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. --- generator/unpack.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/generator/unpack.go b/generator/unpack.go index 73909503..68a7fe49 100644 --- a/generator/unpack.go +++ b/generator/unpack.go @@ -4,6 +4,7 @@ import ( "compress/gzip" "fmt" "io" + "io/fs" "os" "path/filepath" @@ -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 {