Added errors to WriteFileDatabase

Signed-off-by: Morten Linderud <morten@linderud.pw>
This commit is contained in:
Morten Linderud 2021-05-20 00:26:59 +02:00
parent 0d121672ca
commit fe514e1af7
No known key found for this signature in database
GPG Key ID: E742683BA08CB2FF
5 changed files with 17 additions and 10 deletions

View File

@ -25,7 +25,9 @@ var removeFileCmd = &cobra.Command{
os.Exit(1)
}
delete(files, args[0])
sbctl.WriteFileDatabase(sbctl.DBPath, files)
if err := sbctl.WriteFileDatabase(sbctl.DBPath, files); err != nil {
return err
}
return nil
},
}

View File

@ -42,7 +42,9 @@ var signAllCmd = &cobra.Command{
checksum := sbctl.ChecksumFile(entry.File)
entry.Checksum = checksum
files[entry.File] = entry
sbctl.WriteFileDatabase(sbctl.DBPath, files)
if err := sbctl.WriteFileDatabase(sbctl.DBPath, files); err != nil {
return err
}
}
return nil

View File

@ -2,7 +2,6 @@ package main
import (
"errors"
"log"
"os"
"path/filepath"
@ -75,7 +74,7 @@ var verifyCmd = &cobra.Command{
}
return nil
}); err != nil {
log.Println(err)
return err
}
return nil
},

View File

@ -3,7 +3,6 @@ package sbctl
import (
"encoding/json"
"fmt"
"log"
"os"
)
@ -27,15 +26,16 @@ func ReadFileDatabase(dbpath string) (SigningEntries, error) {
return files, nil
}
func WriteFileDatabase(dbpath string, files SigningEntries) {
func WriteFileDatabase(dbpath string, files SigningEntries) error {
data, err := json.MarshalIndent(files, "", " ")
if err != nil {
log.Fatal(err)
return err
}
err = os.WriteFile(dbpath, data, 0644)
if err != nil {
log.Fatal(err)
return err
}
return nil
}
func SigningEntryIter(fn func(s *SigningEntry) error) error {

View File

@ -115,7 +115,9 @@ func Sign(file, output string, enroll bool) error {
checksum := ChecksumFile(file)
entry.Checksum = checksum
files[file] = entry
WriteFileDatabase(DBPath, files)
if err := WriteFileDatabase(DBPath, files); err != nil {
return err
}
} else {
err = SignFile(DBKey, DBCert, file, output, "")
// return early if signing fails
@ -127,7 +129,9 @@ func Sign(file, output string, enroll bool) error {
if enroll {
checksum := ChecksumFile(file)
files[file] = &SigningEntry{File: file, OutputFile: output, Checksum: checksum}
WriteFileDatabase(DBPath, files)
if err := WriteFileDatabase(DBPath, files); err != nil {
return err
}
}
return err