Fix fs error handling

This commit is contained in:
Daniel 2022-10-11 12:22:05 +02:00
parent 93e6672b0c
commit ce0d08ff18
5 changed files with 11 additions and 6 deletions

View file

@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"io"
"io/fs"
"os"
"strings"
@ -81,7 +82,7 @@ var (
if !confirmed {
return nil
}
} else if !os.IsNotExist(err) {
} else if !errors.Is(err, fs.ErrNotExist) {
return fmt.Errorf("failed to access output file: %w", err)
}
}

View file

@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"io"
"io/fs"
"os"
"strings"
@ -70,7 +71,7 @@ var (
if !confirmed {
return nil
}
} else if !os.IsNotExist(err) {
} else if !errors.Is(err, fs.ErrNotExist) {
return fmt.Errorf("failed to access output file: %w", err)
}
}

View file

@ -3,6 +3,7 @@ package filesig
import (
"errors"
"fmt"
"io/fs"
"os"
"strings"
@ -59,7 +60,7 @@ func SignFile(dataFilePath, signatureFilePath string, metaData map[string]string
if err != nil {
return nil, fmt.Errorf("failed to add signature to file: %w", err)
}
case os.IsNotExist(err):
case errors.Is(err, fs.ErrNotExist):
// Make signature section for saving to disk.
newSigFileData, err = MakeSigFileSection(signature)
if err != nil {

View file

@ -3,6 +3,7 @@ package truststores
import (
"errors"
"fmt"
"io/fs"
"os"
"path/filepath"
"strings"
@ -246,7 +247,7 @@ func NewDirTrustStore(storageDir string) (*DirTrustStore, error) {
// validate path
info, err := os.Stat(cleanedPath)
if err != nil {
if os.IsNotExist(err) {
if errors.Is(err, fs.ErrNotExist) {
return nil, fmt.Errorf("trust store does not exist: %w", err)
}
return nil, fmt.Errorf("failed to access trust store: %w", err)

View file

@ -2,6 +2,7 @@ package truststores
import (
"errors"
"io/fs"
"os"
"github.com/safing/jess"
@ -38,7 +39,7 @@ func WriteSignetToFile(signet *jess.Signet, filename string) error {
func LoadSignetFromFile(filename string) (*jess.Signet, error) {
data, err := os.ReadFile(filename)
if err != nil {
if os.IsNotExist(err) {
if errors.Is(err, fs.ErrNotExist) {
return nil, jess.ErrSignetNotFound
}
return nil, err
@ -83,7 +84,7 @@ func WriteEnvelopeToFile(envelope *jess.Envelope, filename string) error {
func LoadEnvelopeFromFile(filename string) (*jess.Envelope, error) {
data, err := os.ReadFile(filename)
if err != nil {
if os.IsNotExist(err) {
if errors.Is(err, fs.ErrNotExist) {
return nil, jess.ErrEnvelopeNotFound
}
return nil, err