Skip to content

Commit

Permalink
refactor(nodebuilder): stick to lock semantics, not file (#3255)
Browse files Browse the repository at this point in the history
Review discussion that did't get to the PR because of automerge
  • Loading branch information
Wondertan authored Mar 13, 2024
1 parent 648f61a commit 4b0586c
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions nodebuilder/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,10 @@ func RemoveConfig(path string) (err error) {
if err != nil {
return fmt.Errorf("locking file: %w", err)
}
defer flk.Close()
if !ok {
return ErrOpened
}
defer flk.Unlock() //nolint:errcheck

return removeConfig(configPath(path))
}
Expand All @@ -124,10 +124,10 @@ func UpdateConfig(tp node.Type, path string) (err error) {
if err != nil {
return fmt.Errorf("locking file: %w", err)
}
defer flk.Close()
if !ok {
return ErrOpened
}
defer flk.Unlock() //nolint:errcheck

newCfg := DefaultConfig(tp)

Expand Down
4 changes: 2 additions & 2 deletions nodebuilder/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ func Init(cfg Config, path string, tp node.Type) error {
if err != nil {
return fmt.Errorf("locking file: %w", err)
}
defer flk.Close()
if !ok {
return ErrOpened
}
defer flk.Unlock() //nolint:errcheck

ksPath := keysPath(path)
err = initDir(ksPath)
Expand Down Expand Up @@ -88,10 +88,10 @@ func Reset(path string, tp node.Type) error {
if err != nil {
return fmt.Errorf("locking file: %w", err)
}
defer flk.Close()
if !ok {
return ErrOpened
}
defer flk.Unlock() //nolint:errcheck

err = resetDir(dataPath(path))
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion nodebuilder/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func TestInitErrForLockedDir(t *testing.T) {
flk := flock.New(lockPath(dir))
_, err := flk.TryLock()
require.NoError(t, err)
defer flk.Close()
defer flk.Unlock() //nolint:errcheck
nodes := []node.Type{node.Light, node.Bridge}

for _, node := range nodes {
Expand Down
4 changes: 2 additions & 2 deletions nodebuilder/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,13 @@ func OpenStore(path string, ring keyring.Keyring) (Store, error) {
}

if !IsInit(path) {
err := errors.Join(ErrNotInited, flk.Close())
err := errors.Join(ErrNotInited, flk.Unlock())
return nil, err
}

ks, err := keystore.NewFSKeystore(keysPath(path), ring)
if err != nil {
err = errors.Join(err, flk.Close())
err = errors.Join(err, flk.Unlock())
return nil, err
}

Expand Down

0 comments on commit 4b0586c

Please sign in to comment.