github.com/erikjuhani/git-gong@v0.0.0-20220213141213-6b9fa82d4e7c/fs/ensure_dir.go (about)

     1  package fs
     2  
     3  import (
     4  	"errors"
     5  	"os"
     6  )
     7  
     8  func EnsureDir(dirname string) error {
     9  	if err := os.Mkdir(dirname, os.ModePerm); os.IsNotExist(err) {
    10  		fileinfo, err := os.Stat(dirname)
    11  		if err != nil {
    12  			return err
    13  		}
    14  
    15  		if fileinfo.IsDir() {
    16  			return nil
    17  		}
    18  
    19  		return errors.New("path is not a directory")
    20  	}
    21  
    22  	return nil
    23  }