pkg/program/shell: MakePathsWithDefaults -> MakePaths.

Also change it to accept and return Paths values (instead of *Paths).
This commit is contained in:
Qi Xiao 2020-04-16 16:39:44 +01:00
parent 094a03ac5b
commit a2a42e2767
3 changed files with 8 additions and 8 deletions

View File

@ -17,8 +17,8 @@ type shellProgram struct {
}
func (sh *shellProgram) Main(fds [3]*os.File, args []string) int {
p := shell.MakePathsWithDefaults(fds[2],
&shell.Paths{Bin: sh.BinPath, Sock: sh.SockPath, Db: sh.DbPath})
p := shell.MakePaths(fds[2],
shell.Paths{Bin: sh.BinPath, Sock: sh.SockPath, Db: sh.DbPath})
if sh.NoRc {
p.Rc = ""
}

View File

@ -23,9 +23,9 @@ type Paths struct {
Bin string
}
// MakePathsWithDefaults tries to populate empty fileds with default values.
func MakePathsWithDefaults(stderr io.Writer, p0 *Paths) *Paths {
p := *p0
// MakePaths makes a populated Paths, using the given overrides.
func MakePaths(stderr io.Writer, overrides Paths) Paths {
p := overrides
setDir(&p.RunDir, "secure run directory", getSecureRunDir, stderr)
if p.RunDir != "" {
setChild(&p.Sock, p.RunDir, "sock")
@ -47,7 +47,7 @@ func MakePathsWithDefaults(stderr io.Writer, p0 *Paths) *Paths {
fmt.Fprintln(stderr, "warning: cannot get executable path:", err)
}
}
return &p
return p
}
func setDir(p *string, what string, f func() (string, error), stderr io.Writer) {

View File

@ -34,8 +34,8 @@ type ExecuteResponse struct {
}
func (web *Web) Main(fds [3]*os.File, _ []string) int {
p := shell.MakePathsWithDefaults(fds[2],
&shell.Paths{Bin: web.BinPath, Sock: web.SockPath, Db: web.DbPath})
p := shell.MakePaths(fds[2],
shell.Paths{Bin: web.BinPath, Sock: web.SockPath, Db: web.DbPath})
ev := shell.InitRuntime(fds[2], p, true)
defer shell.CleanupRuntime(fds[2], ev)