Make Pathname#atomic_write truly atomic
Make Pathname#atomic_write truly atomic

As we know, files cannot be moved across filesystems atomically. In that
case, FileUtils.mv will make a copy. But if we create the temp file in
the same directory as the target, we can avoid this and use File.rename
directly.

Additionally, the rename should be the absolute last step, so that the
original file is preserved if altering ownership and permissions fails.

reitermarkus/brew,nandub/brew,DomT4/brew,Homebrew/brew,zmwangx/brew,reitermarkus/brew,konqui/brew,EricFromCanada/brew,sjackman/homebrew,reelsense/brew,jmsundar/brew,nandub/brew,jmsundar/brew,EricFromCanada/brew,gregory-nisbet/brew,sjackman/homebrew,konqui/brew,claui/brew,vitorgalvao/brew,toonetown/homebrew,MikeMcQuaid/brew,gordonmcshane/homebrew,tonyg/homebrew,mahori/brew,reitermarkus/brew,bfontaine/brew,AnastasiaSulyagina/brew,gregory-nisbet/brew,aw1621107/brew,mgrimes/brew,maxim-belkin/brew,nandub/brew,amar-laksh/brew_sudo,mahori/brew,rwhogg/brew,EricFromCanada/brew,bfontaine/brew,Linuxbrew/brew,AnastasiaSulyagina/brew,hanxue/linuxbrew,vitorgalvao/brew,maxim-belkin/brew,claui/brew,alyssais/brew,reitermarkus/brew,konqui/brew,claui/brew,konqui/brew,alyssais/brew,staticfloat/brew,pseudocody/brew,DomT4/brew,zmwangx/brew,mgrimes/brew,staticfloat/brew,toonetown/homebrew,aw1621107/brew,alyssais/brew,rwhogg/brew,MikeMcQuaid/brew,vitorgalvao/brew,palxex/brew,Linuxbrew/brew,Homebrew/brew,mahori/brew,Linuxbrew/brew,ilovezfs/brew,palxex/brew,mahori/brew,hanxue/linuxbrew,reelsense/brew,mistydemeo/homebrew,pseudocody/brew,amar-laksh/brew_sudo,JCount/brew,JCount/brew,gordonmcshane/homebrew,staticfloat/brew,AnastasiaSulyagina/brew,claui/brew,mistydemeo/homebrew,aw1621107/brew,DomT4/brew,pseudocody/brew,Linuxbrew/brew,Homebrew/brew,gregory-nisbet/brew,rwhogg/brew,zmwangx/brew,muellermartin/dist,tonyg/homebrew,vitorgalvao/brew,muellermartin/dist,toonetown/homebrew,jmsundar/brew,JCount/brew,amar-laksh/brew_sudo,bfontaine/brew,reelsense/brew,JCount/brew,mistydemeo/homebrew,EricFromCanada/brew,hanxue/linuxbrew,palxex/brew,sjackman/homebrew,muellermartin/dist,gordonmcshane/homebrew,MikeMcQuaid/brew,DomT4/brew,maxim-belkin/brew,MikeMcQuaid/brew,tonyg/homebrew,ilovezfs/brew,nandub/brew,sjackman/homebrew,ilovezfs/brew,Homebrew/brew,mgrimes/brew