summaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
authorLibravatar kim <89579420+NyaaaWhatsUpDoc@users.noreply.github.com>2022-11-06 12:30:08 +0000
committerLibravatar GitHub <noreply@github.com>2022-11-06 13:30:08 +0100
commit05a8baa53ae7983b8fa2d79589ff0cab7ab1b22b (patch)
tree041f88f0f035df2c3793565d44700e0e5fe09c2d /internal
parent[docs] add note about Alpha status right at the top (#971) (diff)
downloadgotosocial-05a8baa53ae7983b8fa2d79589ff0cab7ab1b22b.tar.xz
[bugfix] KVStore doesn't like lost+found directory (#972)
* bump go-store version to v2.0.5, init kv.KVStore without initial clean (as we are using for storage, not as a key-value store) Signed-off-by: kim <grufwub@gmail.com> * remove newline Signed-off-by: kim <grufwub@gmail.com> Signed-off-by: kim <grufwub@gmail.com>
Diffstat (limited to 'internal')
-rw-r--r--internal/storage/local.go32
-rw-r--r--internal/storage/storage.go16
2 files changed, 10 insertions, 38 deletions
diff --git a/internal/storage/local.go b/internal/storage/local.go
index 3fde7f0b9..9a5f971a2 100644
--- a/internal/storage/local.go
+++ b/internal/storage/local.go
@@ -20,43 +20,13 @@ package storage
import (
"context"
- "io"
"net/url"
"codeberg.org/gruf/go-store/v2/kv"
- "codeberg.org/gruf/go-store/v2/storage"
)
type Local struct {
- KVStore *kv.KVStore
-}
-
-func (l *Local) Get(ctx context.Context, key string) ([]byte, error) {
- return l.KVStore.Get(ctx, key)
-}
-
-func (l *Local) GetStream(ctx context.Context, key string) (io.ReadCloser, error) {
- return l.KVStore.GetStream(ctx, key)
-}
-
-func (l *Local) PutStream(ctx context.Context, key string, r io.Reader) error {
- err := l.KVStore.PutStream(ctx, key, r)
- if err == storage.ErrAlreadyExists {
- return ErrAlreadyExists
- }
- return err
-}
-
-func (l *Local) Put(ctx context.Context, key string, value []byte) error {
- err := l.KVStore.Put(ctx, key, value)
- if err == storage.ErrAlreadyExists {
- return ErrAlreadyExists
- }
- return err
-}
-
-func (l *Local) Delete(ctx context.Context, key string) error {
- return l.KVStore.Delete(ctx, key)
+ *kv.KVStore
}
func (l *Local) URL(ctx context.Context, key string) *url.URL {
diff --git a/internal/storage/storage.go b/internal/storage/storage.go
index 5d712bc3c..e44c47184 100644
--- a/internal/storage/storage.go
+++ b/internal/storage/storage.go
@@ -33,8 +33,10 @@ import (
"github.com/superseriousbusiness/gotosocial/internal/config"
)
-var ErrNotSupported = errors.New("driver does not suppport functionality")
-var ErrAlreadyExists = errors.New("storage key already exists")
+var (
+ ErrNotSupported = errors.New("driver does not suppport functionality")
+ ErrAlreadyExists = storage.ErrAlreadyExists
+)
// Driver implements the functionality to store and retrieve blobs
// (images,video,audio)
@@ -59,19 +61,19 @@ func AutoConfig() (Driver, error) {
}
return NewS3(mc, config.GetStorageS3BucketName()), nil
case "local":
- storageBasePath := config.GetStorageLocalBasePath()
- storage, err := kv.OpenDisk(storageBasePath, &storage.DiskConfig{
+ basePath := config.GetStorageLocalBasePath()
+ disk, err := storage.OpenDisk(basePath, &storage.DiskConfig{
// Put the store lockfile in the storage dir itself.
// Normally this would not be safe, since we could end up
// overwriting the lockfile if we store a file called 'store.lock'.
// However, in this case it's OK because the keys are set by
// GtS and not the user, so we know we're never going to overwrite it.
- LockFile: path.Join(storageBasePath, "store.lock"),
+ LockFile: path.Join(basePath, "store.lock"),
})
if err != nil {
- return nil, fmt.Errorf("error creating storage backend: %s", err)
+ return nil, fmt.Errorf("error openingdisk storage: %v", err)
}
- return &Local{KVStore: storage}, nil
+ return &Local{kv.New(disk)}, nil
}
return nil, fmt.Errorf("invalid storage backend %s", config.GetStorageBackend())
}