style(storage): привести receiver-ы к первой букве типа
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
@@ -19,9 +19,9 @@ type localSink struct {
|
|||||||
dir string
|
dir string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sink *localSink) Begin(key string) (domain.SinkTx, error) {
|
func (l *localSink) Begin(key string) (domain.SinkTx, error) {
|
||||||
tmpPath := filepath.Join(sink.dir, key+".tmp")
|
tmpPath := filepath.Join(l.dir, key+".tmp")
|
||||||
finalPath := filepath.Join(sink.dir, key)
|
finalPath := filepath.Join(l.dir, key)
|
||||||
|
|
||||||
file, err := os.Create(tmpPath)
|
file, err := os.Create(tmpPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -35,8 +35,8 @@ func (sink *localSink) Begin(key string) (domain.SinkTx, error) {
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sink *localSink) List(prefix string) ([]string, error) {
|
func (l *localSink) List(prefix string) ([]string, error) {
|
||||||
entries, err := os.ReadDir(sink.dir)
|
entries, err := os.ReadDir(l.dir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -56,8 +56,8 @@ func (sink *localSink) List(prefix string) ([]string, error) {
|
|||||||
return keys, nil
|
return keys, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sink *localSink) Remove(key string) error {
|
func (l *localSink) Remove(key string) error {
|
||||||
path := filepath.Join(sink.dir, key)
|
path := filepath.Join(l.dir, key)
|
||||||
return os.Remove(path)
|
return os.Remove(path)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -70,39 +70,39 @@ type localSinkTx struct {
|
|||||||
mu sync.Mutex
|
mu sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
func (transaction *localSinkTx) Write(p []byte) (int, error) {
|
func (t *localSinkTx) Write(p []byte) (int, error) {
|
||||||
transaction.mu.Lock()
|
t.mu.Lock()
|
||||||
defer transaction.mu.Unlock()
|
defer t.mu.Unlock()
|
||||||
|
|
||||||
if transaction.committed || transaction.aborted {
|
if t.committed || t.aborted {
|
||||||
return 0, errors.New("transaction already finished")
|
return 0, errors.New("transaction already finished")
|
||||||
}
|
}
|
||||||
|
|
||||||
return transaction.file.Write(p)
|
return t.file.Write(p)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (transaction *localSinkTx) Commit() error {
|
func (t *localSinkTx) Commit() error {
|
||||||
transaction.mu.Lock()
|
t.mu.Lock()
|
||||||
defer transaction.mu.Unlock()
|
defer t.mu.Unlock()
|
||||||
|
|
||||||
if transaction.committed || transaction.aborted {
|
if t.committed || t.aborted {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
transaction.committed = true
|
t.committed = true
|
||||||
|
|
||||||
if err := transaction.file.Sync(); err != nil {
|
if err := t.file.Sync(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := transaction.file.Close(); err != nil {
|
if err := t.file.Close(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := os.Rename(transaction.tmpPath, transaction.finalPath); err != nil {
|
if err := os.Rename(t.tmpPath, t.finalPath); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
parent, err := os.Open(filepath.Dir(transaction.tmpPath))
|
parent, err := os.Open(filepath.Dir(t.tmpPath))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -115,18 +115,18 @@ func (transaction *localSinkTx) Commit() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (transaction *localSinkTx) Abort() error {
|
func (t *localSinkTx) Abort() error {
|
||||||
transaction.mu.Lock()
|
t.mu.Lock()
|
||||||
defer transaction.mu.Unlock()
|
defer t.mu.Unlock()
|
||||||
|
|
||||||
if transaction.committed || transaction.aborted {
|
if t.committed || t.aborted {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
transaction.aborted = true
|
t.aborted = true
|
||||||
|
|
||||||
_ = transaction.file.Close()
|
_ = t.file.Close()
|
||||||
_ = os.Remove(transaction.tmpPath)
|
_ = os.Remove(t.tmpPath)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user