code: func WriteTmpFile(fs utilfs.Filesystem, path string, data []byte) (tmpPath string, retErr error) {
  	dir := filepath.Dir(path)
  	prefix := tmptag + filepath.Base(path)
  
  	// create the tmp file
  	tmpFile, err := fs.TempFile(dir, prefix)
  	if err != nil {
  		return "", err
  	}
  	defer func() {
  		// close the file, return the close error only if there haven't been any other errors
  		if err := tmpFile.Close(); retErr == nil {
  			retErr = err
  		}
  		// if there was an error writing, syncing, or closing, delete the temporary file and return the error
  		if retErr != nil {
  			if err := fs.Remove(tmpPath); err != nil {
  				retErr = fmt.Errorf("attempted to remove temporary file %q after error %v, but failed due to error: %v", tmpPath, retErr, err)
  			}
  			tmpPath = ""
  		}
  	}()
  
  	// Name() will be an absolute path when using utilfs.DefaultFS, because ioutil.TempFile passes
  	// an absolute path to os.Open, and we ensure similar behavior in utilfs.FakeFS for testing.
  	tmpPath = tmpFile.Name()
  
  	// write data
  	if _, err := tmpFile.Write(data); err != nil {
  		return tmpPath, err
  	}
  	// sync file, to ensure it's written in case a hard reset happens
  	return tmpPath, tmpFile.Sync()
  }
docs: // WriteTmpFile creates a temporary file at `path`, writes `data` into it, and fsyncs the file
  // Expects the parent directory to exist.