-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Always use transaction in JSONFile.Save() #1724
Conversation
@@ -131,9 +153,35 @@ func newJSONFileTransaction(f *JSONFile) (*jsonFileTransaction, error) { | |||
} | |||
|
|||
func (f *JSONFile) Save() error { | |||
tx, txCreated, err := f.getOrMakeTx() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this function be simplified at all? since it's only a 3-liner, maybe don't use a defer
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wouldn't we want Abort to be called if Commit fails?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Absolutely, but can't we do that in the error case of save
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But the Commit happens in capital Save() if it creates a transaction.
If |
It is removed from the ConfigWriter interface. |
PTAL |
👍 |
If one exists, it will be used, otherwise a transaction will be created and used around the save() call. Also, this removes Save() from ConfigWriter interface and cleans up unnecessary usage of Save() outside config.go.
save() uses f.tx.tmpname exclusively
c74d61c
to
5184f5f
Compare
…ot a dir (#1724) * return ErrNotExist if a non-final path element exists but is not a dir * jzila is a firefighter
If one exists, it will be used, otherwise a transaction
will be created and used around the save() call.
Also, this removes Save() from ConfigWriter interface
and cleans up unnecessary usage of Save() outside config.go.
PTAL @maxtaco