[lxc-devel] [lxd/master] lxc/file: Fix pull target logic

stgraber on Github lxc-bot at linuxcontainers.org
Mon Apr 9 22:58:30 UTC 2018


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 354 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20180409/3ecbcf4e/attachment.bin>
-------------- next part --------------
From 37c6c763cbdc3277a6464ef692d295b4dc1e3bf7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Tue, 10 Apr 2018 00:58:08 +0200
Subject: [PATCH] lxc/file: Fix pull target logic
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
 lxc/file.go | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/lxc/file.go b/lxc/file.go
index adde732c0f..84e59d8a44 100644
--- a/lxc/file.go
+++ b/lxc/file.go
@@ -223,7 +223,7 @@ func (c *cmdFilePull) Run(cmd *cobra.Command, args []string) error {
 		if !targetIsDir && len(args)-1 > 1 {
 			return fmt.Errorf(i18n.G("More than one file to download, but target is not a directory"))
 		}
-	} else if strings.HasSuffix(target, string(os.PathSeparator)) || len(args)-1 > 1 || c.file.flagRecursive {
+	} else if strings.HasSuffix(args[len(args)-1], string(os.PathSeparator)) || len(args)-1 > 1 {
 		err := os.MkdirAll(target, 0755)
 		if err != nil {
 			return err
@@ -251,6 +251,14 @@ func (c *cmdFilePull) Run(cmd *cobra.Command, args []string) error {
 		// Deal with recursion
 		if resp.Type == "directory" {
 			if c.file.flagRecursive {
+				if !shared.PathExists(target) {
+					err := os.MkdirAll(target, 0755)
+					if err != nil {
+						return err
+					}
+					targetIsDir = true
+				}
+
 				err := c.file.recursivePullFile(resource.server, pathSpec[0], pathSpec[1], target)
 				if err != nil {
 					return err


More information about the lxc-devel mailing list