Bugfix#2504 Rename of temp file fails.
Bugfix#2504 Rename of temp file fails.

Tempfile was not closed, so rename opertion was failing.
Minor code refactor is done, to make function more readable.

Signed-off-by: Kunal Kushwaha <b1bd878ae25b05ef328fec75ec3b5f4fe91d9ae8@lab.ntt.co.jp>

pottava/machine,aduermael/docker.github.io,JimGalasyn/docker.github.io,skatsuta/machine,ppadala/machine,rillig/docker.github.io,cvstebut/machine,docker/docker.github.io,jzwlqx/denverdino.github.io,larsla/machine,sebadiaz/machine,askb/machine,bdwill/docker.github.io,docker/docker.github.io,jmelis/machine,exoscale/docker-machine,StackPointCloud/machine,johnstep/docker.github.io,bgokden/machine,anweiss/docker.github.io,denverdino/docker.github.io,kacole2/machine,pottava/machine,joaofnfernandes/docker.github.io,jzwlqx/denverdino.github.io,thaJeztah/machine,bdwill/docker.github.io,alexisbellido/docker.github.io,jgsqware/machine,bdwill/docker.github.io,dgageot/machine,docker/machine,JimGalasyn/docker.github.io,danix800/docker.github.io,rillig/docker.github.io,soleo/machine,sanscontext/docker.github.io,faijaz/docker-machine,kunalkushwaha/machine,LuisBosquez/docker.github.io,robertbreker/machine,londoncalling/docker.github.io,SvenDowideit/machine,docker-zh/docker.github.io,bgokden/machine,bdwill/docker.github.io,jsirois/machine,johnstep/docker.github.io,cvstebut/machine,ppadala/machine,zchee/machine,shin-/docker.github.io,menglingwei/machine,Herbis/machine,JohnKDay/machine,londoncalling/docker.github.io,gdevillele/docker.github.io,thaJeztah/docker.github.io,thaJeztah/docker.github.io,LuisBosquez/docker.github.io,londoncalling/docker.github.io,flavio/machine,joeuo/docker.github.io,ppadala/machine,shubheksha/docker.github.io,alexisbellido/docker.github.io,robvanmieghem/machine,faijaz/docker-machine,tyrken/machine,voutilad/machine,denverdino/machine,BSWANG/denverdino.github.io,ibuildthecloud/machine,thaJeztah/docker.github.io,wzymaster/machine,tpires/machine,jeffellin/machine,denverdino/machine,jsirois/machine,kacole2/machine,menglingwei/denverdino.github.io,wzymaster/machine,rillig/docker.github.io,jgsqware/machine,shubheksha/docker.github.io,gdevillele/docker.github.io,otherjason/machine,JohnKDay/machine,miqui/machine,menglingwei/denverdino.github.io,JimGalasyn/docker.github.io,jeanlaurent/machine,anweiss/docker.github.io,JohnKDay/machine,soleo/machine,londoncalling/machine,pottava/machine,zchee/machine,thaJeztah/machine,shin-/docker.github.io,joeuo/docker.github.io,BSWANG/denverdino.github.io,sanscontext/docker.github.io,londoncalling/docker.github.io,BSWANG/denverdino.github.io,LuisBosquez/docker.github.io,menglingwei/denverdino.github.io,rillig/docker.github.io,xinxian0458/machine,exoscale/docker-machine,robertbreker/machine,gdevillele/docker.github.io,LuisBosquez/docker.github.io,phiroict/docker,ibuildthecloud/machine,shubheksha/docker.github.io,BSWANG/denverdino.github.io,skatsuta/machine,troy0820/docker.github.io,menglingwei/denverdino.github.io,johnstep/docker.github.io,aduermael/docker.github.io,SvenDowideit/machine,sebadiaz/machine,miqui/machine,troy0820/docker.github.io,faijaz/docker-machine,flavio/machine,jeffellin/machine,jeffellin/machine,moxiegirl/machine,otherjason/machine,denverdino/docker.github.io,aduermael/docker.github.io,zchee/machine,StackPointCloud/machine,soleo/machine,robvanmieghem/machine,menglingwei/denverdino.github.io,errordeveloper/machine,robertbreker/machine,johnstep/docker.github.io,denverdino/docker.github.io,denverdino/denverdino.github.io,joaofnfernandes/docker.github.io,tpires/machine,voutilad/machine,Herbis/machine,londoncalling/docker.github.io,kunalkushwaha/machine,troy0820/docker.github.io,xinxian0458/machine,docker/docker.github.io,tyrken/machine,tyrken/machine,thaJeztah/docker.github.io,larsla/machine,kunalkushwaha/machine,denverdino/docker.github.io,docker-zh/docker.github.io,jmelis/machine,gdevillele/docker.github.io,gdevillele/docker.github.io,dgageot/machine,juliengarcia/machine,jeanlaurent/machine,shin-/docker.github.io,dweomer/docker-machine,docker-zh/docker.github.io,sanscontext/docker.github.io,menglingwei/machine,juliengarcia/machine,sanscontext/docker.github.io,menglingwei/machine,JimGalasyn/docker.github.io,jzwlqx/denverdino.github.io,alexisbellido/docker.github.io,moxiegirl/machine,danix800/docker.github.io,phiroict/docker,errordeveloper/machine,docker-zh/docker.github.io,bgokden/machine,BSWANG/denverdino.github.io,alexisbellido/docker.github.io,jzwlqx/denverdino.github.io,troy0820/docker.github.io,docker/machine,sanscontext/docker.github.io,denverdino/docker.github.io,jeanlaurent/machine,londoncalling/machine,askb/machine,jzwlqx/denverdino.github.io,joaofnfernandes/docker.github.io,shin-/docker.github.io,joaofnfernandes/docker.github.io,docker/docker.github.io,askb/machine,docker-zh/docker.github.io,denverdino/denverdino.github.io,LuisBosquez/docker.github.io,xinxian0458/machine,denverdino/machine,StackPointCloud/machine,anweiss/docker.github.io,anweiss/docker.github.io,joaofnfernandes/docker.github.io,denverdino/denverdino.github.io,denverdino/denverdino.github.io,robvanmieghem/machine,anweiss/docker.github.io,kacole2/machine,alexisbellido/docker.github.io,danix800/docker.github.io,joeuo/docker.github.io,jmelis/machine,errordeveloper/machine,phiroict/docker,thaJeztah/docker.github.io,docker/docker.github.io,shin-/docker.github.io,jsirois/machine,JimGalasyn/docker.github.io,otherjason/machine,joeuo/docker.github.io,tpires/machine,thaJeztah/machine,danix800/docker.github.io,bdwill/docker.github.io,aduermael/docker.github.io,wzymaster/machine,shubheksha/docker.github.io,sebadiaz/machine,cvstebut/machine,miqui/machine,dweomer/docker-machine,phiroict/docker,johnstep/docker.github.io,juliengarcia/machine,skatsuta/machine,joeuo/docker.github.io,moxiegirl/machine,jgsqware/machine,shubheksha/docker.github.io,denverdino/denverdino.github.io,phiroict/docker