package shell

import (
	
	
	
	

	
)

// Paths keeps all paths required for the Elvish runtime.
type Paths struct {
	RunDir string
	Sock   string

	DataDir string
	Db      string
	Rc      string
	LibDir  string

	Bin string
}

// MakePaths makes a populated Paths, using the given overrides.
func ( io.Writer,  Paths) Paths {
	 := 
	setDir(&.RunDir, "secure run directory", getSecureRunDir, )
	if .RunDir != "" {
		setChild(&.Sock, .RunDir, "sock")
	}

	setDir(&.DataDir, "data directory", ensureDataDir, )
	if .DataDir != "" {
		setChild(&.Db, .DataDir, "db")
		setChild(&.Rc, .DataDir, "rc.elv")
		setChild(&.LibDir, .DataDir, "lib")
	}

	if .Bin == "" {
		,  := os.Executable()
		if  == nil {
			.Bin = 
		} else {
			fmt.Fprintln(, "warning: cannot get executable path:", )
		}
	}
	return 
}

func ( *string,  string,  func() (string, error),  io.Writer) {
	if * == "" {
		,  := ()
		if  == nil {
			* = 
		} else {
			fmt.Fprintf(, "warning: cannot create %v: %v\n", , )
		}
	}
}

func ( *string, ,  string) {
	if * == "" {
		* = filepath.Join(, )
	}
}

// Ensures Elvish's data directory exists, creating it if necessary. It returns
// the path to the data directory (never with a trailing slash) and possible
// error.
func () (string, error) {
	,  := fsutil.GetHome("")
	if  != nil {
		return "", 
	}
	 :=  + "/.elvish"
	return , os.MkdirAll(, 0700)
}