Rename ErrNoSuchFile in store package

This commit is contained in:
Torjus Håkestad 2021-12-05 12:42:22 +01:00
parent 6d6d307a91
commit 6377602033
5 changed files with 13 additions and 13 deletions

View File

@ -65,7 +65,7 @@ func (s *BoltStore) GetFile(id string) (*pb.File, error) {
return nil, fmt.Errorf("error getting file: %w", err) return nil, fmt.Errorf("error getting file: %w", err)
} }
if data == nil { if data == nil {
return nil, ErrNoSuchFile return nil, ErrNoSuchItem
} }
err := proto.Unmarshal(data, &file) err := proto.Unmarshal(data, &file)
@ -98,7 +98,7 @@ func (s *BoltStore) DeleteFile(id string) error {
bkt := t.Bucket(bktKey) bkt := t.Bucket(bktKey)
data := bkt.Get([]byte(id)) data := bkt.Get([]byte(id))
if data == nil { if data == nil {
return ErrNoSuchFile return ErrNoSuchItem
} }
return bkt.Delete([]byte(id)) return bkt.Delete([]byte(id))
}) })
@ -140,7 +140,7 @@ func (s *BoltStore) GetCertificate(id string) (*x509.Certificate, error) {
return nil, err return nil, err
} }
if raw == nil { if raw == nil {
return nil, ErrNoSuchFile return nil, ErrNoSuchItem
} }
cert, err := x509.ParseCertificate(raw) cert, err := x509.ParseCertificate(raw)
@ -269,5 +269,5 @@ func (s *BoltStore) GetUserByUsername(username string) (*pb.User, error) {
if user.Username == username { if user.Username == username {
return &user, nil return &user, nil
} }
return nil, ErrNoSuchFile return nil, ErrNoSuchItem
} }

View File

@ -27,7 +27,7 @@ func (s *FileSystemStore) GetFile(id string) (*pb.File, error) {
f, err := os.Open(path) f, err := os.Open(path)
if err != nil { if err != nil {
if os.IsNotExist(os.ErrNotExist) { if os.IsNotExist(os.ErrNotExist) {
return nil, ErrNoSuchFile return nil, ErrNoSuchItem
} }
return nil, fmt.Errorf("unable to open file: %w", err) return nil, fmt.Errorf("unable to open file: %w", err)
} }

View File

@ -43,7 +43,7 @@ func (s *MemoryStore) GetFile(id string) (*pb.File, error) {
return file, nil return file, nil
} }
return nil, ErrNoSuchFile return nil, ErrNoSuchItem
} }
func (s *MemoryStore) StoreFile(file *pb.File) (string, error) { func (s *MemoryStore) StoreFile(file *pb.File) (string, error) {
@ -62,7 +62,7 @@ func (s *MemoryStore) DeleteFile(id string) error {
s.filesLock.Lock() s.filesLock.Lock()
defer s.filesLock.Unlock() defer s.filesLock.Unlock()
if _, ok := s.files[id]; !ok { if _, ok := s.files[id]; !ok {
return ErrNoSuchFile return ErrNoSuchItem
} }
delete(s.files, id) delete(s.files, id)
@ -95,7 +95,7 @@ func (s *MemoryStore) GetCertificate(id string) (*x509.Certificate, error) {
data, ok := s.certs[id] data, ok := s.certs[id]
if !ok { if !ok {
// TODO: Make separate error, or rename error // TODO: Make separate error, or rename error
return nil, ErrNoSuchFile return nil, ErrNoSuchItem
} }
return x509.ParseCertificate(data) return x509.ParseCertificate(data)
@ -118,7 +118,7 @@ func (s *MemoryStore) GetKey(id string) (*ecdsa.PrivateKey, error) {
defer s.keyLock.RUnlock() defer s.keyLock.RUnlock()
data, ok := s.keys[id] data, ok := s.keys[id]
if !ok { if !ok {
return nil, ErrNoSuchFile return nil, ErrNoSuchItem
} }
return x509.ParseECPrivateKey(data) return x509.ParseECPrivateKey(data)
@ -167,7 +167,7 @@ func (s *MemoryStore) GetUser(id string) (*pb.User, error) {
user, ok := s.users[id] user, ok := s.users[id]
if !ok { if !ok {
// TODO: Update error // TODO: Update error
return nil, ErrNoSuchFile return nil, ErrNoSuchItem
} }
return user, nil return user, nil
} }
@ -191,5 +191,5 @@ func (s *MemoryStore) GetUserByUsername(username string) (*pb.User, error) {
return user, nil return user, nil
} }
} }
return nil, ErrNoSuchFile return nil, ErrNoSuchItem
} }

View File

@ -8,7 +8,7 @@ import (
"gitea.benny.dog/torjus/ezshare/pb" "gitea.benny.dog/torjus/ezshare/pb"
) )
var ErrNoSuchFile = fmt.Errorf("no such file") var ErrNoSuchItem = fmt.Errorf("no such item")
type FileStore interface { type FileStore interface {
GetFile(id string) (*pb.File, error) GetFile(id string) (*pb.File, error)

View File

@ -68,7 +68,7 @@ func doFileStoreTest(s store.FileStore, t *testing.T) {
t.Fatalf("Unable to delete file: %s", err) t.Fatalf("Unable to delete file: %s", err)
} }
if _, err := s.GetFile(id); err != store.ErrNoSuchFile { if _, err := s.GetFile(id); err != store.ErrNoSuchItem {
t.Fatalf("Getting deleted file returned wrong error: %s", err) t.Fatalf("Getting deleted file returned wrong error: %s", err)
} }
}) })