summaryrefslogtreecommitdiff
path: root/pkg
diff options
context:
space:
mode:
Diffstat (limited to 'pkg')
-rw-r--r--pkg/api/handlers/utils/containers.go35
-rw-r--r--pkg/machine/pull.go8
2 files changed, 33 insertions, 10 deletions
diff --git a/pkg/api/handlers/utils/containers.go b/pkg/api/handlers/utils/containers.go
index c4c9cc2ea..6c708f74e 100644
--- a/pkg/api/handlers/utils/containers.go
+++ b/pkg/api/handlers/utils/containers.go
@@ -7,6 +7,7 @@ import (
"strconv"
"time"
+ "github.com/containers/podman/v3/libpod/events"
"github.com/containers/podman/v3/pkg/domain/entities"
"github.com/containers/podman/v3/pkg/domain/infra/abi"
@@ -175,7 +176,7 @@ func waitDockerCondition(ctx context.Context, containerName string, interval tim
var code int32
switch dockerCondition {
case "next-exit":
- code, err = waitNextExit(containerWait)
+ code, err = waitNextExit(ctx, containerName)
case "removed":
code, err = waitRemoved(containerWait)
case "not-running", "":
@@ -202,12 +203,32 @@ func waitRemoved(ctrWait containerWaitFn) (int32, error) {
return code, err
}
-func waitNextExit(ctrWait containerWaitFn) (int32, error) {
- _, err := ctrWait(define.ContainerStateRunning)
- if err != nil {
- return -1, err
- }
- return ctrWait(notRunningStates...)
+func waitNextExit(ctx context.Context, containerName string) (int32, error) {
+ runtime := ctx.Value("runtime").(*libpod.Runtime)
+ containerEngine := &abi.ContainerEngine{Libpod: runtime}
+ eventChannel := make(chan *events.Event)
+ errChannel := make(chan error)
+ opts := entities.EventsOptions{
+ EventChan: eventChannel,
+ Filter: []string{"event=died", fmt.Sprintf("container=%s", containerName)},
+ Stream: true,
+ }
+
+ // ctx is used to cancel event watching goroutine
+ ctx, cancel := context.WithCancel(ctx)
+ defer cancel()
+ go func() {
+ errChannel <- containerEngine.Events(ctx, opts)
+ }()
+
+ evt, ok := <-eventChannel
+ if ok {
+ return int32(evt.ContainerExitCode), nil
+ }
+ // if ok == false then containerEngine.Events() has exited
+ // it may happen if request was canceled (e.g. client closed connection prematurely) or
+ // the server is in process of shutting down
+ return -1, <-errChannel
}
func waitNotRunning(ctrWait containerWaitFn) (int32, error) {
diff --git a/pkg/machine/pull.go b/pkg/machine/pull.go
index d9f34057f..68bb551dc 100644
--- a/pkg/machine/pull.go
+++ b/pkg/machine/pull.go
@@ -162,7 +162,11 @@ func Decompress(localPath, uncompressedPath string) error {
return err
}
- if compressionType := archive.DetectCompression(sourceFile); compressionType.Extension() == "tar.xz" {
+ compressionType := archive.DetectCompression(sourceFile)
+ if compressionType != archive.Uncompressed {
+ fmt.Println("Extracting compressed file")
+ }
+ if compressionType == archive.Xz {
return decompressXZ(localPath, uncompressedFileWriter)
}
return decompressEverythingElse(localPath, uncompressedFileWriter)
@@ -172,7 +176,6 @@ func Decompress(localPath, uncompressedPath string) error {
// Maybe extracting then renameing is a good idea here..
// depends on xz: not pre-installed on mac, so it becomes a brew dependency
func decompressXZ(src string, output io.Writer) error {
- fmt.Println("Extracting compressed file")
cmd := exec.Command("xzcat", "-k", src)
//cmd := exec.Command("xz", "-d", "-k", "-v", src)
stdOut, err := cmd.StdoutPipe()
@@ -190,7 +193,6 @@ func decompressXZ(src string, output io.Writer) error {
}
func decompressEverythingElse(src string, output io.Writer) error {
- fmt.Println("Extracting compressed file")
f, err := os.Open(src)
if err != nil {
return err