Skip to content

Commit 3c8294d

Browse files
authored
Merge pull request #27 from mask-pp/fix_bug_1
Panic will be touched when mergedDir is empty.
2 parents 63ea4f9 + ae2c50e commit 3c8294d

File tree

1 file changed

+8
-13
lines changed

1 file changed

+8
-13
lines changed

internal/command/cli.go

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,6 @@ func containerMode(name string) string {
246246
// CreateContainer create new container and attach target container resource
247247
func (cli *DebugCli) CreateContainer(attachContainer string, options execOptions) (string, error) {
248248
var mounts []mount.Mount
249-
var mergedDir string
250-
var ok bool
251249
ctx, cancel := cli.withContent(cli.config.Timeout)
252250
info, err := cli.client.ContainerInspect(ctx, attachContainer)
253251
cancel()
@@ -258,19 +256,16 @@ func (cli *DebugCli) CreateContainer(attachContainer string, options execOptions
258256
return "", errors.Errorf("container: `%s` is not running", attachContainer)
259257
}
260258
attachContainer = info.ID
261-
mountDir, ok := info.GraphDriver.Data["MergedDir"]
262-
if ok {
263-
mergedDir = mountDir
259+
mergedDir, ok := info.GraphDriver.Data["MergedDir"]
260+
if !ok || mergedDir == "" {
261+
return "", fmt.Errorf("container: `%s` not found merged dir", attachContainer)
264262
}
265263
if cli.config.MountDir != "" {
266-
mounts = []mount.Mount{}
267-
if mergedDir != "" {
268-
mounts = append(mounts, mount.Mount{
269-
Type: "bind",
270-
Source: mergedDir,
271-
Target: cli.config.MountDir,
272-
})
273-
}
264+
mounts = append(mounts, mount.Mount{
265+
Type: "bind",
266+
Source: mergedDir,
267+
Target: cli.config.MountDir,
268+
})
274269
for _, i := range info.Mounts {
275270
var mountType = i.Type
276271
if i.Type == "volume" {

0 commit comments

Comments
 (0)