func NewAtomicFileWriter(filename string, perm os.FileMode) (io.WriteCloser, error) {
	f, err := ioutil.TempFile(filepath.Dir(filename), ".tmp-"+filepath.Base(filename))
	if err != nil {
		return nil, err
	}
	abspath, err := filepath.Abs(filename)
	if err != nil {
		return nil, err
	}
	return &atomicFileWriter{
		f:  f,
		fn: abspath,
	}, nil
}
NewAtomicFileWriter returns WriteCloser so that writing to it writes to a
temporary file and closing it atomically changes the temporary file to
destination path. Writing and closing concurrently is not allowed.
package ioutils
import (
	"io"
	"io/ioutil"
	"os"
	"path/filepath"
)