src.elv.sh@v0.21.0-dev.0.20240515223629-06979efb9a2a/pkg/shell/paths_windows.go (about)

     1  package shell
     2  
     3  import (
     4  	"fmt"
     5  	"os"
     6  	"path/filepath"
     7  
     8  	"golang.org/x/sys/windows"
     9  	"src.elv.sh/pkg/env"
    10  )
    11  
    12  var (
    13  	defaultConfigHome = roamingAppData
    14  	defaultDataHome   = localAppData
    15  	defaultDataDirs   = []string{}
    16  	defaultStateHome  = localAppData
    17  )
    18  
    19  func localAppData() (string, error) {
    20  	return windows.KnownFolderPath(windows.FOLDERID_LocalAppData, windows.KF_FLAG_CREATE)
    21  }
    22  
    23  func roamingAppData() (string, error) {
    24  	return windows.KnownFolderPath(windows.FOLDERID_RoamingAppData, windows.KF_FLAG_CREATE)
    25  }
    26  
    27  // getSecureRunDir stats elvish-$USERNAME under the default temp dir, creating
    28  // it if it doesn't yet exist, and return the directory name.
    29  func secureRunDir() (string, error) {
    30  	username := os.Getenv(env.USERNAME)
    31  
    32  	runDir := filepath.Join(os.TempDir(), "elvish-"+username)
    33  	err := os.MkdirAll(runDir, 0700)
    34  	if err != nil {
    35  		return "", fmt.Errorf("mkdir: %v", err)
    36  	}
    37  
    38  	return runDir, nil
    39  }