This PR does two things, because one lead to the other: - Move the leveldb specific stuff into a small "backend" package that defines a backend interface and the leveldb implementation. This allows, potentially, in the future, switching the db implementation so another KV store should we wish to do so. - Add proper error handling all along the way. The db and backend packages are now errcheck clean. However, I drew the line at modifying the FileSet API in order to keep this manageable and not continue refactoring all of the rest of Syncthing. As such, the FileSet methods still panic on database errors, except for the "database is closed" error which is instead handled by silently returning as quickly as possible, with the assumption that we're anyway "on the way out".
This commit is contained in:
@@ -13,8 +13,8 @@ import (
|
||||
// The database is where we store the virtual mtimes
|
||||
type database interface {
|
||||
Bytes(key string) (data []byte, ok bool)
|
||||
PutBytes(key string, data []byte)
|
||||
Delete(key string)
|
||||
PutBytes(key string, data []byte) error
|
||||
Delete(key string) error
|
||||
}
|
||||
|
||||
// The MtimeFS is a filesystem with nanosecond mtime precision, regardless
|
||||
|
||||
@@ -236,8 +236,9 @@ func TestMtimeFSInsensitive(t *testing.T) {
|
||||
|
||||
type mapStore map[string][]byte
|
||||
|
||||
func (s mapStore) PutBytes(key string, data []byte) {
|
||||
func (s mapStore) PutBytes(key string, data []byte) error {
|
||||
s[key] = data
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s mapStore) Bytes(key string) (data []byte, ok bool) {
|
||||
@@ -245,8 +246,9 @@ func (s mapStore) Bytes(key string) (data []byte, ok bool) {
|
||||
return
|
||||
}
|
||||
|
||||
func (s mapStore) Delete(key string) {
|
||||
func (s mapStore) Delete(key string) error {
|
||||
delete(s, key)
|
||||
return nil
|
||||
}
|
||||
|
||||
// failChtimes does nothing, and fails
|
||||
|
||||
Reference in New Issue
Block a user