Skip to content

Commit ab0f6f3

Browse files
nmeumanatol
authored andcommitted
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.
1 parent e867f92 commit ab0f6f3

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

generator/unpack.go

+13-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"compress/gzip"
55
"fmt"
66
"io"
7+
"io/fs"
78
"os"
89
"path/filepath"
910

@@ -133,16 +134,27 @@ func runUnpack() error {
133134
}
134135

135136
func runCat() error {
137+
var foundFile bool
136138
fn := func(hdr *cpio.Header, r *cpio.Reader) error {
137139
if hdr.Name == opts.CatCommand.Args.File {
138140
if _, err := io.Copy(os.Stdout, r); err != nil {
139141
return err
140142
}
143+
144+
foundFile = true
141145
return errStop
142146
}
143147
return nil
144148
}
145-
return processImage(opts.CatCommand.Args.Image, fn)
149+
150+
err := processImage(opts.CatCommand.Args.Image, fn)
151+
if err != nil {
152+
return err
153+
} else if !foundFile {
154+
return fs.ErrNotExist
155+
}
156+
157+
return nil
146158
}
147159

148160
func runLs() error {

0 commit comments

Comments
 (0)