add f.Close() after dockerignore.ReadAll(f) before return err#33860
add f.Close() after dockerignore.ReadAll(f) before return err#33860cpuguy83 merged 1 commit intomoby:masterfrom
Conversation
builder/remotecontext/detect.go
Outdated
There was a problem hiding this comment.
Not sure this will work; f will no longer be closed before it's being removed in the filesToRemove loop below
Perhaps add f.Close() inside the if err != nil { instead?
There was a problem hiding this comment.
Looks like that's happening indeed;
06:41:21 time="2017-06-28T06:41:21Z" level=error msg="failed to remove .dockerignore: remove C:\\Users\\ContainerAdministrator\\AppData\\Local\\Temp\\builder-dockerignore-process-test250723583\\.dockerignore: The process cannot access the file because it is being used by another process."
06:41:21 2017/06/28 06:41:21 Directory should contain exactly 1 file(s), got 2
boaz0
left a comment
There was a problem hiding this comment.
LGTM but I prefer to have f.Close() before return err. Read more about why here: https://lk4d4.darth.io/posts/defer/
|
@ripcurld0 the current ( |
cc4c411 to
2069b70
Compare
|
ok, has put f.Close() before return err. |
|
@thaJeztah thanks. I did miss it. |
|
@ripcurld0 FYI, I think @LK4D4's point was that in small functions you don't want to use |
|
@cyphar I totally agree. I just think this is one of the cases I wouldn't use |
|
So we just need a single (By the way the commit message is no longer in sync with the code itself.) |
Ah, yes, that should work obviously
Good catch: @lixiaobing1 can you update your PR with the above changes? |
7208f5c to
4a101e2
Compare
|
@thaJeztah ok, commit message has been updated. |
|
Looks like there's a gofmt issue; |
|
sorry, has commit again. |
Signed-off-by: lixiaobing10051267 <li.xiaobing1@zte.com.cn> Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
add f.Close() after dockerignore.ReadAll(f) before return err.