Write metadata.type reliably
Write metadata.type reliably

Summary:
If an IOException occurs while writing metadata.type, buck-out is left
in a weird, unrecoverable state in which metadata exists, but there's no record
of how it's stored.  Make sure we never get into this state by writing to a temp
file and moving it into place (rather than simply creating/truncating it and
hoping we can successfully write).

Test Plan:
Local builds, CI.  I haven't been able to reproduce the exact failure
locally.  I tried mounting buck-out/ on a small fs to get to "No space left on
device", but that was just dying without creating the metadata.type file.

Reviewed By: marcinkosiba

fbshipit-source-id: ca4636e

Addepar/buck,vschs007/buck,nguyentruongtho/buck,k21/buck,rmaz/buck,brettwooldridge/buck,marcinkwiatkowski/buck,zhan-xiong/buck,JoelMarcey/buck,shybovycha/buck,SeleniumHQ/buck,vschs007/buck,shs96c/buck,rmaz/buck,romanoid/buck,zhan-xiong/buck,LegNeato/buck,nguyentruongtho/buck,ilya-klyuchnikov/buck,Addepar/buck,dsyang/buck,JoelMarcey/buck,marcinkwiatkowski/buck,marcinkwiatkowski/buck,robbertvanginkel/buck,shybovycha/buck,shs96c/buck,dsyang/buck,clonetwin26/buck,zhan-xiong/buck,romanoid/buck,robbertvanginkel/buck,rmaz/buck,SeleniumHQ/buck,robbertvanginkel/buck,nguyentruongtho/buck,brettwooldridge/buck,facebook/buck,Addepar/buck,SeleniumHQ/buck,facebook/buck,shybovycha/buck,romanoid/buck,dsyang/buck,vschs007/buck,ilya-klyuchnikov/buck,dsyang/buck,clonetwin26/buck,zhan-xiong/buck,clonetwin26/buck,shybovycha/buck,vschs007/buck,zhan-xiong/buck,ilya-klyuchnikov/buck,marcinkwiatkowski/buck,facebook/buck,rmaz/buck,shs96c/buck,zpao/buck,LegNeato/buck,rmaz/buck,kageiit/buck,Addepar/buck,vschs007/buck,Addepar/buck,rmaz/buck,k21/buck,romanoid/buck,dsyang/buck,ilya-klyuchnikov/buck,marcinkwiatkowski/buck,JoelMarcey/buck,kageiit/buck,robbertvanginkel/buck,romanoid/buck,kageiit/buck,robbertvanginkel/buck,Addepar/buck,romanoid/buck,clonetwin26/buck,dsyang/buck,zhan-xiong/buck,LegNeato/buck,k21/buck,ilya-klyuchnikov/buck,LegNeato/buck,k21/buck,ilya-klyuchnikov/buck,SeleniumHQ/buck,shs96c/buck,vschs007/buck,SeleniumHQ/buck,zhan-xiong/buck,marcinkwiatkowski/buck,clonetwin26/buck,marcinkwiatkowski/buck,JoelMarcey/buck,LegNeato/buck,shs96c/buck,facebook/buck,rmaz/buck,LegNeato/buck,rmaz/buck,Addepar/buck,romanoid/buck,dsyang/buck,robbertvanginkel/buck,brettwooldridge/buck,marcinkwiatkowski/buck,shybovycha/buck,SeleniumHQ/buck,robbertvanginkel/buck,SeleniumHQ/buck,k21/buck,JoelMarcey/buck,SeleniumHQ/buck,kageiit/buck,romanoid/buck,clonetwin26/buck,JoelMarcey/buck,kageiit/buck,shybovycha/buck,marcinkwiatkowski/buck,JoelMarcey/buck,rmaz/buck,JoelMarcey/buck,shs96c/buck,brettwooldridge/buck,shs96c/buck,shybovycha/buck,rmaz/buck,zhan-xiong/buck,ilya-klyuchnikov/buck,ilya-klyuchnikov/buck,dsyang/buck,brettwooldridge/buck,LegNeato/buck,ilya-klyuchnikov/buck,kageiit/buck,clonetwin26/buck,JoelMarcey/buck,zpao/buck,Addepar/buck,vschs007/buck,brettwooldridge/buck,brettwooldridge/buck,zhan-xiong/buck,k21/buck,marcinkwiatkowski/buck,ilya-klyuchnikov/buck,romanoid/buck,k21/buck,zpao/buck,clonetwin26/buck,romanoid/buck,Addepar/buck,shs96c/buck,dsyang/buck,marcinkwiatkowski/buck,shybovycha/buck,clonetwin26/buck,Addepar/buck,k21/buck,romanoid/buck,shybovycha/buck,LegNeato/buck,vschs007/buck,zhan-xiong/buck,JoelMarcey/buck,SeleniumHQ/buck,k21/buck,shs96c/buck,zhan-xiong/buck,zhan-xiong/buck,LegNeato/buck,dsyang/buck,vschs007/buck,SeleniumHQ/buck,clonetwin26/buck,robbertvanginkel/buck,shs96c/buck,ilya-klyuchnikov/buck,shybovycha/buck,SeleniumHQ/buck,clonetwin26/buck,SeleniumHQ/buck,Addepar/buck,k21/buck,k21/buck,facebook/buck,shs96c/buck,romanoid/buck,robbertvanginkel/buck,rmaz/buck,vschs007/buck,romanoid/buck,clonetwin26/buck,kageiit/buck,ilya-klyuchnikov/buck,facebook/buck,Addepar/buck,brettwooldridge/buck,LegNeato/buck,shybovycha/buck,JoelMarcey/buck,brettwooldridge/buck,marcinkwiatkowski/buck,JoelMarcey/buck,brettwooldridge/buck,robbertvanginkel/buck,brettwooldridge/buck,JoelMarcey/buck,LegNeato/buck,marcinkwiatkowski/buck,robbertvanginkel/buck,k21/buck,nguyentruongtho/buck,shybovycha/buck,zpao/buck,facebook/buck,robbertvanginkel/buck,clonetwin26/buck,vschs007/buck,zpao/buck,zpao/buck,zpao/buck,shs96c/buck,zhan-xiong/buck,dsyang/buck,SeleniumHQ/buck,ilya-klyuchnikov/buck,rmaz/buck,vschs007/buck,vschs007/buck,dsyang/buck,Addepar/buck,brettwooldridge/buck,nguyentruongtho/buck,LegNeato/buck,dsyang/buck,shs96c/buck,rmaz/buck,nguyentruongtho/buck,robbertvanginkel/buck,shybovycha/buck,k21/buck,brettwooldridge/buck,nguyentruongtho/buck,LegNeato/buck