autorun 추가
This commit is contained in:
@ -142,14 +142,47 @@ func zipLogFiles(storageRoot string, req *shared.UploadRequest) (string, []strin
|
||||
return f.Name(), matches, nil
|
||||
}
|
||||
|
||||
func prepareProcessLaunch(storageRoot string, req *shared.StartProcessRequest) *procmeta {
|
||||
func prepareProcessLaunch(storageRoot string, req *shared.StartProcessRequest) (*procmeta, error) {
|
||||
if len(req.Args) == 0 {
|
||||
return nil
|
||||
return nil, errors.New("args is empty")
|
||||
}
|
||||
|
||||
if req.Version == "latest" {
|
||||
entries, err := os.ReadDir(path.Join(storageRoot, req.Name))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var latestTimestamp time.Time
|
||||
var latestVersion string
|
||||
for _, entry := range entries {
|
||||
if !entry.IsDir() {
|
||||
continue
|
||||
}
|
||||
|
||||
fi, err := entry.Info()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
createTime := fi.ModTime()
|
||||
if latestTimestamp.Before(createTime) {
|
||||
latestTimestamp = fi.ModTime()
|
||||
latestVersion = fi.Name()
|
||||
}
|
||||
}
|
||||
|
||||
if len(latestVersion) > 0 {
|
||||
req.Version = latestVersion
|
||||
}
|
||||
}
|
||||
|
||||
verpath := path.Join(storageRoot, req.Name, req.Version)
|
||||
fi, err := os.Stat(verpath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err == nil && fi.IsDir() {
|
||||
if fi.IsDir() {
|
||||
exefile := "./" + path.Clean(strings.TrimPrefix(req.Args[0], "/"))
|
||||
os.Chmod(path.Join(verpath, exefile), 0777)
|
||||
|
||||
@ -158,7 +191,8 @@ func prepareProcessLaunch(storageRoot string, req *shared.StartProcessRequest) *
|
||||
for i, arg := range req.Args {
|
||||
expanded[i] = os.ExpandEnv(arg)
|
||||
}
|
||||
exename := path.Join(path.Dir(exef), verpath, exefile)
|
||||
|
||||
exename := path.Join(path.Dir(strings.ReplaceAll(exef, "\\", "/")), verpath, exefile)
|
||||
|
||||
logger.Println("exefile :", exefile)
|
||||
logger.Println("verpath :", verpath)
|
||||
@ -181,9 +215,9 @@ func prepareProcessLaunch(storageRoot string, req *shared.StartProcessRequest) *
|
||||
verpath: verpath,
|
||||
state: int32(protos.ProcessState_Stopped),
|
||||
stdin: stdin,
|
||||
}
|
||||
}, nil
|
||||
}
|
||||
return nil
|
||||
return nil, errors.New("not found")
|
||||
}
|
||||
|
||||
func makeLogFilePrefix(meta *procmeta, index int) string {
|
||||
@ -392,10 +426,11 @@ func (hc *houstonClient) launch(meta *procmeta) error {
|
||||
var errPrepareprocessLaunchFailed = errors.New("prepareProcessLaunch failed")
|
||||
|
||||
func (hc *houstonClient) startChildProcess(req *shared.StartProcessRequest, op protos.OperationClient) error {
|
||||
meta := prepareProcessLaunch(hc.config.StorageRoot, req)
|
||||
if meta == nil {
|
||||
return errPrepareprocessLaunchFailed
|
||||
meta, err := prepareProcessLaunch(hc.config.StorageRoot, req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := hc.launch(meta); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user