diff --git a/pkg/adapters/storage/local/local.go b/pkg/adapters/storage/local/local.go index 6441c6c..4e1e1a2 100644 --- a/pkg/adapters/storage/local/local.go +++ b/pkg/adapters/storage/local/local.go @@ -19,9 +19,9 @@ type localSink struct { dir string } -func (sink *localSink) Begin(key string) (domain.SinkTx, error) { - tmpPath := filepath.Join(sink.dir, key+".tmp") - finalPath := filepath.Join(sink.dir, key) +func (l *localSink) Begin(key string) (domain.SinkTx, error) { + tmpPath := filepath.Join(l.dir, key+".tmp") + finalPath := filepath.Join(l.dir, key) file, err := os.Create(tmpPath) if err != nil { @@ -35,8 +35,8 @@ func (sink *localSink) Begin(key string) (domain.SinkTx, error) { }, nil } -func (sink *localSink) List(prefix string) ([]string, error) { - entries, err := os.ReadDir(sink.dir) +func (l *localSink) List(prefix string) ([]string, error) { + entries, err := os.ReadDir(l.dir) if err != nil { return nil, err } @@ -56,8 +56,8 @@ func (sink *localSink) List(prefix string) ([]string, error) { return keys, nil } -func (sink *localSink) Remove(key string) error { - path := filepath.Join(sink.dir, key) +func (l *localSink) Remove(key string) error { + path := filepath.Join(l.dir, key) return os.Remove(path) } @@ -70,39 +70,39 @@ type localSinkTx struct { mu sync.Mutex } -func (transaction *localSinkTx) Write(p []byte) (int, error) { - transaction.mu.Lock() - defer transaction.mu.Unlock() +func (t *localSinkTx) Write(p []byte) (int, error) { + t.mu.Lock() + defer t.mu.Unlock() - if transaction.committed || transaction.aborted { + if t.committed || t.aborted { return 0, errors.New("transaction already finished") } - return transaction.file.Write(p) + return t.file.Write(p) } -func (transaction *localSinkTx) Commit() error { - transaction.mu.Lock() - defer transaction.mu.Unlock() +func (t *localSinkTx) Commit() error { + t.mu.Lock() + defer t.mu.Unlock() - if transaction.committed || transaction.aborted { + if t.committed || t.aborted { return nil } - transaction.committed = true + t.committed = true - if err := transaction.file.Sync(); err != nil { + if err := t.file.Sync(); err != nil { return err } - if err := transaction.file.Close(); err != nil { + if err := t.file.Close(); err != nil { return err } - if err := os.Rename(transaction.tmpPath, transaction.finalPath); err != nil { + if err := os.Rename(t.tmpPath, t.finalPath); err != nil { return err } - parent, err := os.Open(filepath.Dir(transaction.tmpPath)) + parent, err := os.Open(filepath.Dir(t.tmpPath)) if err != nil { return err } @@ -115,18 +115,18 @@ func (transaction *localSinkTx) Commit() error { return nil } -func (transaction *localSinkTx) Abort() error { - transaction.mu.Lock() - defer transaction.mu.Unlock() +func (t *localSinkTx) Abort() error { + t.mu.Lock() + defer t.mu.Unlock() - if transaction.committed || transaction.aborted { + if t.committed || t.aborted { return nil } - transaction.aborted = true + t.aborted = true - _ = transaction.file.Close() - _ = os.Remove(transaction.tmpPath) + _ = t.file.Close() + _ = os.Remove(t.tmpPath) return nil }