github.com/bananabytelabs/wazero@v0.0.0-20240105073314-54b22a776da8/internal/gojs/config/config.go (about) 1 // Package config exists to avoid dependency cycles when keeping most of gojs 2 // code internal. 3 package config 4 5 import ( 6 "os" 7 "path/filepath" 8 9 "github.com/bananabytelabs/wazero/internal/platform" 10 ) 11 12 type Config struct { 13 OsWorkdir bool 14 15 // Workdir is the actual working directory value. 16 Workdir string 17 Umask uint32 18 } 19 20 func NewConfig() *Config { 21 return &Config{ 22 OsWorkdir: false, 23 Workdir: "/", 24 Umask: uint32(0o0022), 25 } 26 } 27 28 func (c *Config) Clone() *Config { 29 ret := *c // copy except maps which share a ref 30 return &ret 31 } 32 33 func (c *Config) Init() error { 34 if c.OsWorkdir { 35 workdir, err := os.Getwd() 36 if err != nil { 37 return err 38 } 39 // Ensure if used on windows, the input path is translated to a POSIX one. 40 workdir = platform.ToPosixPath(workdir) 41 // Strip the volume of the path, for example C:\ 42 c.Workdir = workdir[len(filepath.VolumeName(workdir)):] 43 } 44 return nil 45 }