github.com/cybriq/giocore@v0.0.7-0.20210703034601-cfb9cb5f3900/gpu/internal/convertshaders/workdir.go (about)

     1  // SPDX-License-Identifier: Unlicense OR MIT
     2  
     3  package main
     4  
     5  import (
     6  	"fmt"
     7  	"io/ioutil"
     8  	"os"
     9  	"path/filepath"
    10  	"strings"
    11  )
    12  
    13  type WorkDir string
    14  
    15  func (wd WorkDir) Dir(path string) WorkDir {
    16  	dirname := filepath.Join(string(wd), path)
    17  	if err := os.Mkdir(dirname, 0755); err != nil {
    18  		if !os.IsExist(err) {
    19  			fmt.Fprintf(os.Stderr, "failed to create %q: %v\n", dirname, err)
    20  		}
    21  	}
    22  	return WorkDir(dirname)
    23  }
    24  
    25  func (wd WorkDir) Path(path ...string) (fullpath string) {
    26  	return filepath.Join(string(wd), strings.Join(path, "."))
    27  }
    28  
    29  func (wd WorkDir) WriteFile(path string, data []byte) error {
    30  	err := ioutil.WriteFile(path, data, 0644)
    31  	if err != nil {
    32  		return fmt.Errorf("unable to create %v: %w", path, err)
    33  	}
    34  	return nil
    35  }