code: func (w *AtomicWriter) writePayloadToDir(payload map[string]FileProjection, dir string) error {
  	for userVisiblePath, fileProjection := range payload {
  		content := fileProjection.Data
  		mode := os.FileMode(fileProjection.Mode)
  		fullPath := filepath.Join(dir, userVisiblePath)
  		baseDir, _ := filepath.Split(fullPath)
  
  		err := os.MkdirAll(baseDir, os.ModePerm)
  		if err != nil {
  			klog.Errorf("%s: unable to create directory %s: %v", w.logContext, baseDir, err)
  			return err
  		}
  
  		err = ioutil.WriteFile(fullPath, content, mode)
  		if err != nil {
  			klog.Errorf("%s: unable to write file %s with mode %v: %v", w.logContext, fullPath, mode, err)
  			return err
  		}
  		// Chmod is needed because ioutil.WriteFile() ends up calling
  		// open(2) to create the file, so the final mode used is "mode &
  		// ~umask". But we want to make sure the specified mode is used
  		// in the file no matter what the umask is.
  		err = os.Chmod(fullPath, mode)
  		if err != nil {
  			klog.Errorf("%s: unable to write file %s with mode %v: %v", w.logContext, fullPath, mode, err)
  		}
  	}
  
  	return nil
  }
docs: // writePayloadToDir writes the given payload to the given directory.  The
  // directory must exist.