gtsocial-umbx

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 05a8baa53ae7983b8fa2d79589ff0cab7ab1b22b
parent 298a7ad21b367912340201bc76e3e23249043814
Author: kim <89579420+NyaaaWhatsUpDoc@users.noreply.github.com>
Date:   Sun,  6 Nov 2022 12:30:08 +0000

[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:
Mcmd/gotosocial/action/server/server.go | 1-
Mgo.mod | 2+-
Mgo.sum | 4++--
Minternal/storage/local.go | 32+-------------------------------
Minternal/storage/storage.go | 16+++++++++-------
Mvendor/codeberg.org/gruf/go-store/v2/kv/store.go | 16+++++++++++-----
Mvendor/modules.txt | 2+-
7 files changed, 25 insertions(+), 48 deletions(-)

diff --git a/cmd/gotosocial/action/server/server.go b/cmd/gotosocial/action/server/server.go @@ -104,7 +104,6 @@ var Start action.GTSAction = func(ctx context.Context) error { typeConverter := typeutils.NewConverter(dbService) // Open the storage backend - storage, err := gtsstorage.AutoConfig() if err != nil { return fmt.Errorf("error creating storage backend: %w", err) diff --git a/go.mod b/go.mod @@ -12,7 +12,7 @@ require ( codeberg.org/gruf/go-logger/v2 v2.2.1 codeberg.org/gruf/go-mutexes v1.1.3 codeberg.org/gruf/go-runners v1.3.1 - codeberg.org/gruf/go-store/v2 v2.0.4 + codeberg.org/gruf/go-store/v2 v2.0.5 github.com/buckket/go-blurhash v1.1.0 github.com/coreos/go-oidc/v3 v3.4.0 github.com/disintegration/imaging v1.6.2 diff --git a/go.sum b/go.sum @@ -95,8 +95,8 @@ codeberg.org/gruf/go-runners v1.3.1 h1:d/OQMMMiA6yPaDSbSr0/Jc+lucWmm7AiAZjWffpNK codeberg.org/gruf/go-runners v1.3.1/go.mod h1:rl0EdZNozkRMb21DAtOL5L4oTfmslYQdZgq2RMMc/H4= codeberg.org/gruf/go-sched v1.1.1 h1:YtLSQhpypzuD3HTup5oF7LLWB79gTL4nqW06kH4Vwks= codeberg.org/gruf/go-sched v1.1.1/go.mod h1:SRcdP/5qim+EBT3n3r4aUra1C30yPqV4OJOXuqvgdQM= -codeberg.org/gruf/go-store/v2 v2.0.4 h1:CpGkJUz7qINh3krjtR6dKmKwJKjprbEKKq4dWF+AemI= -codeberg.org/gruf/go-store/v2 v2.0.4/go.mod h1:vKId86ET4ZzG1tE1dMNkfV66rZkcsyqt64UhKt6EYfc= +codeberg.org/gruf/go-store/v2 v2.0.5 h1:AbOka6LkyT9jobPYfK3h5f5dPqx5AjFPhaaqdOWkGyA= +codeberg.org/gruf/go-store/v2 v2.0.5/go.mod h1:vKId86ET4ZzG1tE1dMNkfV66rZkcsyqt64UhKt6EYfc= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= diff --git 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 @@ -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()) } diff --git a/vendor/codeberg.org/gruf/go-store/v2/kv/store.go b/vendor/codeberg.org/gruf/go-store/v2/kv/store.go @@ -38,10 +38,7 @@ func OpenBlock(path string, cfg *storage.BlockConfig) (*KVStore, error) { } func OpenMemory(overwrites bool) *KVStore { - return &KVStore{ - mu: mutexes.NewMap(-1, -1), - st: storage.OpenMemory(100, overwrites), - } + return New(storage.OpenMemory(100, overwrites)) } func OpenS3(endpoint string, bucket string, cfg *storage.S3Config) (*KVStore, error) { @@ -55,6 +52,7 @@ func OpenS3(endpoint string, bucket string, cfg *storage.S3Config) (*KVStore, er return OpenStorage(storage) } +// OpenStorage will return a new KVStore instance based on Storage, performing an initial storage.Clean(). func OpenStorage(storage storage.Storage) (*KVStore, error) { // Perform initial storage clean err := storage.Clean(context.Background()) @@ -63,10 +61,18 @@ func OpenStorage(storage storage.Storage) (*KVStore, error) { } // Return new KVStore + return New(storage), nil +} + +// New will simply return a new KVStore instance based on Storage. +func New(storage storage.Storage) *KVStore { + if storage == nil { + panic("nil storage") + } return &KVStore{ mu: mutexes.NewMap(-1, -1), st: storage, - }, nil + } } // RLock acquires a read-lock on supplied key, returning unlock function. diff --git a/vendor/modules.txt b/vendor/modules.txt @@ -50,7 +50,7 @@ codeberg.org/gruf/go-runners # codeberg.org/gruf/go-sched v1.1.1 ## explicit; go 1.19 codeberg.org/gruf/go-sched -# codeberg.org/gruf/go-store/v2 v2.0.4 +# codeberg.org/gruf/go-store/v2 v2.0.5 ## explicit; go 1.19 codeberg.org/gruf/go-store/v2/kv codeberg.org/gruf/go-store/v2/storage