Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion pkg/internal/filesystem/lock.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ func ReadOnlyLock(path string) (file *os.File, err error) {
func commonlock(path string, mode lockType) (file *os.File, err error) {
defer func() {
if err != nil {
err = errors.Join(ErrLockFail, err, file.Close())
err = errors.Join(ErrLockFail, err)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The file still has to be closed unless it is nil

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, I'll add a nil check on the file.

if file != nil {
err = errors.Join(err, file.Close())
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not:

err = errors.Join(ErrLockFail, err)
if file != nil {
  err = errors.Join(err, file.Close())
}

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes! better! no nested if else

}
}()

Expand Down
Loading