Skip to content

cli/config/configfile: Make sure to not leak a temp config behind and improve unit tests #1366

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

tsuna
Copy link
Contributor

@tsuna tsuna commented Sep 12, 2018

This is a small followup change to #1359. It addresses the astute observation from @thaJeztah that we can potentially leak temp files in the config directory. While I couldn't easily test this particular failure from the unit test, I took the opportunity to expand the unit test to cover a few failure modes.

cc @vdemeester — thanks guys.

- A picture of a cute animal (not mandatory but encouraged)

🦋

In the unlikely event that we fail to rename the temp config file to the
destination file, don't leave the temp config file behind as this could
cause temp files to pile up in ~/.docker for example if there is a
permission problem.

Signed-off-by: Benoit Sigoure <tsunanet@gmail.com>
Signed-off-by: Benoit Sigoure <tsunanet@gmail.com>
Copy link
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -183,10 +183,10 @@ func (configFile *ConfigFile) Save() error {
if err != nil {
return err
}
defer os.Remove(temp.Name())
Copy link
Member

Choose a reason for hiding this comment

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

this would also attempt to remove temp.Name() in the happy case (i.e., it being succesfully renamed); guess that's not a problem.

Copy link
Collaborator

@vdemeester vdemeester left a comment

Choose a reason for hiding this comment

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

Hum, the new test is failing though 😓

@thaJeztah
Copy link
Member

oh! hm...

@tsuna
Copy link
Contributor Author

tsuna commented Sep 14, 2018

I haven't yet had time to figure out why this is failing on CirleCI, it's as if the test's attempt to make the test directory read-only wasn't actually making it read-only... maybe they do something funky with the filesystem there. 🤔

I'll follow up as soon as I have a few free cycles, sorry guys.

@thaJeztah
Copy link
Member

Could it be because the tests run docker-in-docker, and tests are running as root?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants