Fix fs error handling
This commit is contained in:
parent
93e6672b0c
commit
ce0d08ff18
5 changed files with 11 additions and 6 deletions
|
@ -4,6 +4,7 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"io/fs"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
@ -81,7 +82,7 @@ var (
|
||||||
if !confirmed {
|
if !confirmed {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
} else if !os.IsNotExist(err) {
|
} else if !errors.Is(err, fs.ErrNotExist) {
|
||||||
return fmt.Errorf("failed to access output file: %w", err)
|
return fmt.Errorf("failed to access output file: %w", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"io/fs"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
@ -70,7 +71,7 @@ var (
|
||||||
if !confirmed {
|
if !confirmed {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
} else if !os.IsNotExist(err) {
|
} else if !errors.Is(err, fs.ErrNotExist) {
|
||||||
return fmt.Errorf("failed to access output file: %w", err)
|
return fmt.Errorf("failed to access output file: %w", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ package filesig
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io/fs"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
@ -59,7 +60,7 @@ func SignFile(dataFilePath, signatureFilePath string, metaData map[string]string
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to add signature to file: %w", err)
|
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.
|
// Make signature section for saving to disk.
|
||||||
newSigFileData, err = MakeSigFileSection(signature)
|
newSigFileData, err = MakeSigFileSection(signature)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -3,6 +3,7 @@ package truststores
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io/fs"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -246,7 +247,7 @@ func NewDirTrustStore(storageDir string) (*DirTrustStore, error) {
|
||||||
// validate path
|
// validate path
|
||||||
info, err := os.Stat(cleanedPath)
|
info, err := os.Stat(cleanedPath)
|
||||||
if err != nil {
|
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("trust store does not exist: %w", err)
|
||||||
}
|
}
|
||||||
return nil, fmt.Errorf("failed to access trust store: %w", err)
|
return nil, fmt.Errorf("failed to access trust store: %w", err)
|
||||||
|
|
|
@ -2,6 +2,7 @@ package truststores
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"io/fs"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/safing/jess"
|
"github.com/safing/jess"
|
||||||
|
@ -38,7 +39,7 @@ func WriteSignetToFile(signet *jess.Signet, filename string) error {
|
||||||
func LoadSignetFromFile(filename string) (*jess.Signet, error) {
|
func LoadSignetFromFile(filename string) (*jess.Signet, error) {
|
||||||
data, err := os.ReadFile(filename)
|
data, err := os.ReadFile(filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if os.IsNotExist(err) {
|
if errors.Is(err, fs.ErrNotExist) {
|
||||||
return nil, jess.ErrSignetNotFound
|
return nil, jess.ErrSignetNotFound
|
||||||
}
|
}
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -83,7 +84,7 @@ func WriteEnvelopeToFile(envelope *jess.Envelope, filename string) error {
|
||||||
func LoadEnvelopeFromFile(filename string) (*jess.Envelope, error) {
|
func LoadEnvelopeFromFile(filename string) (*jess.Envelope, error) {
|
||||||
data, err := os.ReadFile(filename)
|
data, err := os.ReadFile(filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if os.IsNotExist(err) {
|
if errors.Is(err, fs.ErrNotExist) {
|
||||||
return nil, jess.ErrEnvelopeNotFound
|
return nil, jess.ErrEnvelopeNotFound
|
||||||
}
|
}
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
Loading…
Add table
Reference in a new issue