-
Notifications
You must be signed in to change notification settings - Fork 2k
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
base: master
Are you sure you want to change the base?
Conversation
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>
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.
LGTM
@@ -183,10 +183,10 @@ func (configFile *ConfigFile) Save() error { | |||
if err != nil { | |||
return err | |||
} | |||
defer os.Remove(temp.Name()) |
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.
this would also attempt to remove temp.Name()
in the happy case (i.e., it being succesfully renamed); guess that's not a problem.
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.
Hum, the new test is failing though 😓
oh! hm... |
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. |
Could it be because the tests run docker-in-docker, and tests are running as |
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)
🦋