summaryrefslogtreecommitdiff
path: root/pkg/varlinkapi/images.go
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/varlinkapi/images.go')
-rw-r--r--pkg/varlinkapi/images.go73
1 files changed, 70 insertions, 3 deletions
diff --git a/pkg/varlinkapi/images.go b/pkg/varlinkapi/images.go
index 77df77a29..a27bdb9e5 100644
--- a/pkg/varlinkapi/images.go
+++ b/pkg/varlinkapi/images.go
@@ -776,9 +776,6 @@ func (i *LibpodAPI) ImageSave(call iopodman.VarlinkCall, options iopodman.ImageS
c <- err
close(c)
}()
-
- // TODO When pull output gets fixed for the remote client, we need to look into how we can turn below
- // into something re-usable. it is in build too
var log []string
done := false
for {
@@ -835,3 +832,73 @@ func (i *LibpodAPI) ImageSave(call iopodman.VarlinkCall, options iopodman.ImageS
}
return call.ReplyPushImage(br)
}
+
+// LoadImage ...
+func (i *LibpodAPI) LoadImage(call iopodman.VarlinkCall, name, inputFile string, deleteInputFile, quiet bool) error {
+ var (
+ names string
+ writer io.Writer
+ err error
+ )
+ if !quiet {
+ writer = os.Stderr
+ }
+
+ if call.WantsMore() {
+ call.Continues = true
+ }
+ output := bytes.NewBuffer([]byte{})
+
+ c := make(chan error)
+ go func() {
+ names, err = i.Runtime.LoadImage(getContext(), name, inputFile, writer, "")
+ c <- err
+ close(c)
+ }()
+
+ var log []string
+ done := false
+ for {
+ line, err := output.ReadString('\n')
+ if err == nil {
+ log = append(log, line)
+ continue
+ } else if err == io.EOF {
+ select {
+ case err := <-c:
+ if err != nil {
+ logrus.Error(err)
+ return call.ReplyErrorOccurred(err.Error())
+ }
+ done = true
+ default:
+ if !call.WantsMore() {
+ time.Sleep(1 * time.Second)
+ break
+ }
+ br := iopodman.MoreResponse{
+ Logs: log,
+ }
+ call.ReplyLoadImage(br)
+ log = []string{}
+ }
+ } else {
+ return call.ReplyErrorOccurred(err.Error())
+ }
+ if done {
+ break
+ }
+ }
+ call.Continues = false
+
+ br := iopodman.MoreResponse{
+ Logs: log,
+ Id: names,
+ }
+ if deleteInputFile {
+ if err := os.Remove(inputFile); err != nil {
+ logrus.Errorf("unable to delete input file %s", inputFile)
+ }
+ }
+ return call.ReplyLoadImage(br)
+}