Commit 51178b3d authored by protolambda's avatar protolambda

op-program: kv-store style change replace os.Is(Not)Exist with errors.Is call

parent 472ea471
...@@ -2,6 +2,7 @@ package kvstore ...@@ -2,6 +2,7 @@ package kvstore
import ( import (
"encoding/hex" "encoding/hex"
"errors"
"fmt" "fmt"
"io" "io"
"os" "os"
...@@ -32,7 +33,7 @@ func (d *DiskKV) pathKey(k common.Hash) string { ...@@ -32,7 +33,7 @@ func (d *DiskKV) pathKey(k common.Hash) string {
func (d *DiskKV) Put(k common.Hash, v []byte) error { func (d *DiskKV) Put(k common.Hash, v []byte) error {
f, err := os.OpenFile(d.pathKey(k), os.O_WRONLY|os.O_CREATE|os.O_EXCL|os.O_TRUNC, diskPermission) f, err := os.OpenFile(d.pathKey(k), os.O_WRONLY|os.O_CREATE|os.O_EXCL|os.O_TRUNC, diskPermission)
if err != nil { if err != nil {
if os.IsExist(err) { if errors.Is(err, os.ErrExist) {
return ErrAlreadyExists return ErrAlreadyExists
} }
return fmt.Errorf("failed to open new pre-image file %s: %w", k, err) return fmt.Errorf("failed to open new pre-image file %s: %w", k, err)
...@@ -50,7 +51,7 @@ func (d *DiskKV) Put(k common.Hash, v []byte) error { ...@@ -50,7 +51,7 @@ func (d *DiskKV) Put(k common.Hash, v []byte) error {
func (d *DiskKV) Get(k common.Hash) ([]byte, error) { func (d *DiskKV) Get(k common.Hash) ([]byte, error) {
f, err := os.OpenFile(d.pathKey(k), os.O_RDONLY, diskPermission) f, err := os.OpenFile(d.pathKey(k), os.O_RDONLY, diskPermission)
if err != nil { if err != nil {
if os.IsNotExist(err) { if errors.Is(err, os.ErrNotExist) {
return nil, ErrNotFound return nil, ErrNotFound
} }
return nil, fmt.Errorf("failed to open pre-image file %s: %w", k, err) return nil, fmt.Errorf("failed to open pre-image file %s: %w", k, err)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment