sbctl/sign: the -o option would fail on non-existing output file

A few options where mixes around during the refactor. We also need to
capture the off case of failing signature verification on the output
file when it doesn't exist.

Signed-off-by: Morten Linderud <morten@linderud.pw>
This commit is contained in:
Morten Linderud 2021-06-28 12:34:19 +02:00
parent 1614cfbd2e
commit 78cdabfa6d
No known key found for this signature in database
GPG Key ID: E742683BA08CB2FF
1 changed files with 7 additions and 2 deletions

View File

@ -177,9 +177,14 @@ func SignFile(key, cert, file, output, checksum string) error {
// Let's check if we have signed it already AND the original file hasn't changed
ok, err := VerifyFile(cert, output)
if err != nil {
if errors.Is(err, os.ErrNotExist) && (file != output) {
// if the file does not exist and file is not the same as output
// then we just catch the error and continue. This is expected
// behaviour
} else if err != nil {
return err
}
chk, err := ChecksumFile(file)
if err != nil {
return err
@ -224,7 +229,7 @@ func SignFile(key, cert, file, output, checksum string) error {
if err != nil {
return err
}
if err = os.WriteFile(file, b, si.Mode()); err != nil {
if err = os.WriteFile(output, b, si.Mode()); err != nil {
return err
}