The following pull request was submitted through Github.
It can be accessed and reviewed at: https://github.com/lxc/lxd/pull/2515

This e-mail was sent by the LXC bot, direct replies will not reach the author
unless they happen to be subscribed to this list.

=== Description (from pull-request) ===
Closes #2508

Signed-off-by: St├ęphane Graber <stgra...@ubuntu.com>
From 36755bdbfae33e0a568e9d10e9b70169565c861c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgra...@ubuntu.com>
Date: Mon, 17 Oct 2016 16:47:32 -0400
Subject: [PATCH] Don't make unnecessary image copies
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Closes #2508

Signed-off-by: St├ęphane Graber <stgra...@ubuntu.com>
---
 lxd/images.go | 23 +++++++++++------------
 1 file changed, 11 insertions(+), 12 deletions(-)

diff --git a/lxd/images.go b/lxd/images.go
index afaa514..daae70b 100644
--- a/lxd/images.go
+++ b/lxd/images.go
@@ -468,14 +468,14 @@ func getImgPostInfo(d *Daemon, r *http.Request,
        sha256 := sha256.New()
        var size int64
 
-       // Create a temporary file for the image tarball
-       imageTarf, err := ioutil.TempFile(builddir, "lxd_tar_")
-       if err != nil {
-               return info, err
-       }
-       defer os.Remove(imageTarf.Name())
-
        if ctype == "multipart/form-data" {
+               // Create a temporary file for the image tarball
+               imageTarf, err := ioutil.TempFile(builddir, "lxd_tar_")
+               if err != nil {
+                       return info, err
+               }
+               defer os.Remove(imageTarf.Name())
+
                // Parse the POST data
                post.Seek(0, 0)
                mr := multipart.NewReader(post, ctypeParams["boundary"])
@@ -577,9 +577,8 @@ func getImgPostInfo(d *Daemon, r *http.Request,
                }
        } else {
                post.Seek(0, 0)
-               size, err = io.Copy(io.MultiWriter(imageTarf, sha256), post)
+               size, err = io.Copy(sha256, post)
                info.Size = size
-               imageTarf.Close()
                logger.Debug("Tar size", log.Ctx{"size": size})
                if err != nil {
                        logger.Error(
@@ -605,7 +604,7 @@ func getImgPostInfo(d *Daemon, r *http.Request,
                        return info, err
                }
 
-               imageMeta, err = getImageMetadata(imageTarf.Name())
+               imageMeta, err = getImageMetadata(post.Name())
                if err != nil {
                        logger.Error(
                                "Failed to get image metadata",
@@ -614,13 +613,13 @@ func getImgPostInfo(d *Daemon, r *http.Request,
                }
 
                imgfname := shared.VarPath("images", info.Fingerprint)
-               err = shared.FileMove(imageTarf.Name(), imgfname)
+               err = shared.FileMove(post.Name(), imgfname)
                if err != nil {
                        logger.Error(
                                "Failed to move the tarfile",
                                log.Ctx{
                                        "err":    err,
-                                       "source": imageTarf.Name(),
+                                       "source": post.Name(),
                                        "dest":   imgfname})
                        return info, err
                }
_______________________________________________
lxc-devel mailing list
lxc-devel@lists.linuxcontainers.org
http://lists.linuxcontainers.org/listinfo/lxc-devel

Reply via email to