Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
CSDN实习生计划
Gitpod
提交
a4956795
G
Gitpod
项目概览
CSDN实习生计划
/
Gitpod
通知
0
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
Gitpod
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
a4956795
编写于
1月 15, 2021
作者:
C
Christian Weichel
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[supervisor] Provide workdir when opening and listing terminals
上级
9336b090
变更
3
展开全部
隐藏空白更改
内联
并排
Showing
3 changed file
with
187 addition
and
138 deletion
+187
-138
components/supervisor-api/go/terminal.pb.go
components/supervisor-api/go/terminal.pb.go
+158
-128
components/supervisor-api/terminal.proto
components/supervisor-api/terminal.proto
+4
-2
components/supervisor/pkg/terminal/service.go
components/supervisor/pkg/terminal/service.go
+25
-8
未找到文件。
components/supervisor-api/go/terminal.pb.go
浏览文件 @
a4956795
此差异已折叠。
点击以展开。
components/supervisor-api/terminal.proto
浏览文件 @
a4956795
...
...
@@ -48,7 +48,7 @@ service TerminalService {
}
message
OpenTerminalRequest
{
reserved
1
;
string
workdir
=
1
;
map
<
string
,
string
>
env
=
2
;
map
<
string
,
string
>
annotations
=
3
;
}
...
...
@@ -72,7 +72,9 @@ message ListTerminalsResponse {
repeated
string
command
=
2
;
string
title
=
3
;
int64
pid
=
4
;
map
<
string
,
string
>
annotations
=
5
;
string
initial_workdir
=
5
;
string
current_workdir
=
6
;
map
<
string
,
string
>
annotations
=
7
;
}
repeated
Terminal
terminals
=
1
;
...
...
components/supervisor/pkg/terminal/service.go
浏览文件 @
a4956795
...
...
@@ -6,9 +6,11 @@ package terminal
import
(
"context"
"fmt"
"io"
"os"
"os/exec"
"path/filepath"
"time"
"github.com/creack/pty"
...
...
@@ -73,7 +75,11 @@ func (srv *MuxTerminalService) Open(ctx context.Context, req *api.OpenTerminalRe
// req.Annotations override options.Annotations.
func
(
srv
*
MuxTerminalService
)
OpenWithOptions
(
ctx
context
.
Context
,
req
*
api
.
OpenTerminalRequest
,
options
TermOptions
)
(
*
api
.
OpenTerminalResponse
,
error
)
{
cmd
:=
exec
.
Command
(
srv
.
DefaultShell
)
cmd
.
Dir
=
srv
.
DefaultWorkdir
if
req
.
Workdir
==
""
{
cmd
.
Dir
=
srv
.
DefaultWorkdir
}
else
{
cmd
.
Dir
=
req
.
Workdir
}
cmd
.
Env
=
append
(
srv
.
Env
,
"TERM=xterm-color"
)
for
key
,
value
:=
range
req
.
Env
{
cmd
.
Env
=
append
(
cmd
.
Env
,
key
+
"="
+
value
)
...
...
@@ -115,16 +121,27 @@ func (srv *MuxTerminalService) List(ctx context.Context, req *api.ListTerminalsR
res
:=
make
([]
*
api
.
ListTerminalsResponse_Terminal
,
0
,
len
(
srv
.
Mux
.
terms
))
for
alias
,
term
:=
range
srv
.
Mux
.
terms
{
var
pid
int64
if
term
.
Command
.
Process
!=
nil
{
pid
=
int64
(
term
.
Command
.
Process
.
Pid
)
var
(
pid
int64
cwd
string
err
error
)
if
proc
:=
term
.
Command
.
Process
;
proc
!=
nil
{
pid
=
int64
(
proc
.
Pid
)
cwd
,
err
=
filepath
.
EvalSymlinks
(
fmt
.
Sprintf
(
"/proc/%d/cwd"
,
pid
))
if
err
!=
nil
{
log
.
WithError
(
err
)
.
WithField
(
"pid"
,
pid
)
.
Warn
(
"unable to resolve terminal's current working dir"
)
cwd
=
term
.
Command
.
Dir
}
}
res
=
append
(
res
,
&
api
.
ListTerminalsResponse_Terminal
{
Alias
:
alias
,
Command
:
term
.
Command
.
Args
,
Pid
:
pid
,
Annotations
:
term
.
Annotations
,
Alias
:
alias
,
Command
:
term
.
Command
.
Args
,
Pid
:
pid
,
InitialWorkdir
:
term
.
Command
.
Dir
,
CurrentWorkdir
:
cwd
,
Annotations
:
term
.
Annotations
,
})
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录