From 7fe5090efa31826b76eabad681c7237712ac1a7e Mon Sep 17 00:00:00 2001 From: mountain Date: Fri, 27 Sep 2024 15:26:51 +0900 Subject: [PATCH] =?UTF-8?q?latest=20=EB=B2=84=EC=A0=84=20=EC=98=B5?= =?UTF-8?q?=EC=85=98=EC=9D=84=20=ED=94=84=EB=A1=9C=EC=84=B8=EC=8A=A4=20?= =?UTF-8?q?=EC=9E=AC=EC=8B=9C=EC=9E=91=EC=8B=9C=EC=97=90=EB=8F=84=20?= =?UTF-8?q?=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/client.go | 25 +++++++++++++++---------- client/operation.go | 26 ++++++++++++++------------ 2 files changed, 29 insertions(+), 22 deletions(-) diff --git a/client/client.go b/client/client.go index 8ae8962..373eaa7 100644 --- a/client/client.go +++ b/client/client.go @@ -91,16 +91,17 @@ type HoustonClient interface { var seq = int32(1) type procmeta struct { - id int32 - cmd *exec.Cmd - name string - args []string - version string - verpath string - recover bool - state int32 - stdin io.WriteCloser - logfile string + id int32 + cmd *exec.Cmd + name string + args []string + version string + verpath string + recover bool + state int32 + stdin io.WriteCloser + logfile string + keepLatest bool } func (pm *procmeta) isState(s protos.ProcessState) bool { @@ -362,6 +363,10 @@ func NewClient(standalone bool) (HoustonClient, error) { proc.cmd.Process.Release() if proc.isState(protos.ProcessState_Restart) { + if proc.keepLatest { + proc.version = "latest" + } + if err := hc.startChildProcess(&shared.StartProcessRequest{ Version: proc.version, Name: proc.name, diff --git a/client/operation.go b/client/operation.go index 489cbb7..c8cd90e 100644 --- a/client/operation.go +++ b/client/operation.go @@ -150,6 +150,7 @@ func prepareProcessLaunch(storageRoot string, req *shared.StartProcessRequest) ( return nil, errors.New("args is empty") } + foundVersion := req.Version if req.Version == "latest" { entries, err := os.ReadDir(path.Join(storageRoot, req.Name)) if err != nil { @@ -175,11 +176,11 @@ func prepareProcessLaunch(storageRoot string, req *shared.StartProcessRequest) ( } if len(latestVersion) > 0 { - req.Version = latestVersion + foundVersion = latestVersion } } - verpath := path.Join(storageRoot, req.Name, req.Version) + verpath := path.Join(storageRoot, req.Name, foundVersion) fi, err := os.Stat(verpath) if err != nil { return nil, err @@ -210,16 +211,17 @@ func prepareProcessLaunch(storageRoot string, req *shared.StartProcessRequest) ( seq++ return &procmeta{ - id: seq, - cmd: cmd, - name: req.Name, - args: req.Args, - version: req.Version, - recover: req.AutoRestart, - verpath: verpath, - state: int32(protos.ProcessState_Stopped), - stdin: stdin, - logfile: req.OutputLogFile, + id: seq, + cmd: cmd, + name: req.Name, + args: req.Args, + version: foundVersion, + recover: req.AutoRestart, + verpath: verpath, + state: int32(protos.ProcessState_Stopped), + stdin: stdin, + logfile: req.OutputLogFile, + keepLatest: req.Version == "latest", }, nil } return nil, errors.New("not found")