Skip to content
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

Merged
merged 2 commits into from
Jan 13, 2016
Merged

Conversation

patrickxb
Copy link
Contributor

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

@@ -131,9 +153,35 @@ func newJSONFileTransaction(f *JSONFile) (*jsonFileTransaction, error) {
}

func (f *JSONFile) Save() error {
tx, txCreated, err := f.getOrMakeTx()
Copy link
Contributor

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?

Copy link
Contributor Author

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?

Copy link
Contributor

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?

Copy link
Contributor Author

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.

@maxtaco
Copy link
Contributor

maxtaco commented Jan 13, 2016

If Save is only called from the various Set* functions, can we remove it from the ConfigWriter interface?

@patrickxb
Copy link
Contributor Author

It is removed from the ConfigWriter interface.

@patrickxb
Copy link
Contributor Author

PTAL

@maxtaco
Copy link
Contributor

maxtaco commented Jan 13, 2016

👍

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
@patrickxb patrickxb force-pushed the patrickxb/CORE-2354 branch from c74d61c to 5184f5f Compare January 13, 2016 21:54
@patrickxb patrickxb merged commit 5184f5f into master Jan 13, 2016
@patrickxb patrickxb deleted the patrickxb/CORE-2354 branch January 13, 2016 21:54
jzila pushed a commit that referenced this pull request Jan 5, 2019
…ot a dir (#1724)

* return ErrNotExist if a non-final path element exists but is not a dir

* jzila is a firefighter
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants