The following pull request was submitted through Github. It can be accessed and reviewed at: https://github.com/lxc/lxd/pull/2559
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) ===
From 6f0d82f7209a5ce4cd533d1dc4c2d7574d8a717a Mon Sep 17 00:00:00 2001 From: Tycho Andersen <tycho.ander...@canonical.com> Date: Tue, 25 Oct 2016 15:00:43 -0600 Subject: [PATCH 1/2] client: fix mkdir -p / Signed-off-by: Tycho Andersen <tycho.ander...@canonical.com> --- client.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/client.go b/client.go index 4309cb6..49fa8e3 100644 --- a/client.go +++ b/client.go @@ -1836,6 +1836,11 @@ func (c *Client) MkdirP(container string, p string, mode os.FileMode) error { return fmt.Errorf("This function isn't supported by public remotes.") } + /* special case, every container has a /, we don't need to do anything */ + if p == "/" { + return nil + } + parts := strings.Split(p, "/") i := len(parts) From 570d4de1803a125f4b818404374730660b71ae06 Mon Sep 17 00:00:00 2001 From: Tycho Andersen <tycho.ander...@canonical.com> Date: Tue, 25 Oct 2016 15:02:11 -0600 Subject: [PATCH 2/2] lxc file: normalize paths before sending them to the server Note that we don't need to normalize the path on file pull, becuase LXD will tell us whether it's a file or directory. Closes #2557 Signed-off-by: Tycho Andersen <tycho.ander...@canonical.com> --- lxc/file.go | 11 +++++++++++ test/suites/filemanip.sh | 3 +++ 2 files changed, 14 insertions(+) diff --git a/lxc/file.go b/lxc/file.go index cd00d55..f610f5f 100644 --- a/lxc/file.go +++ b/lxc/file.go @@ -74,6 +74,17 @@ func (c *fileCmd) push(config *lxd.Config, send_file_perms bool, args []string) return fmt.Errorf(i18n.G("Invalid target %s"), target) } + /* Fix up the path. Let's: + * 1. re-add the leading / that got stripped from the SplitN + * 2. clean it and remove any /./, /../, /////, etc. + * 3. keep the trailing slash if it had one, since we use it via + * filepath.Split below + */ + pathSpec[1] = filepath.Clean("/" + pathSpec[1]) + if target[len(target)-1] == '/' { + pathSpec[1] = pathSpec[1] + "/" + } + targetPath := pathSpec[1] remote, container := config.ParseRemoteAndContainer(pathSpec[0]) diff --git a/test/suites/filemanip.sh b/test/suites/filemanip.sh index d59d08c..64503a6 100644 --- a/test/suites/filemanip.sh +++ b/test/suites/filemanip.sh @@ -40,5 +40,8 @@ test_filemanip() { lxc file pull filemanip/tmp/this/is/a/nonexistent/directory/foo "${TEST_DIR}" [ "$(cat "${TEST_DIR}"/foo)" = "foo" ] + lxc file push -p "${TEST_DIR}"/source/foo filemanip/. + [ "$(lxc exec filemanip cat /foo)" = "foo" ] + lxc delete filemanip -f }
_______________________________________________ lxc-devel mailing list lxc-devel@lists.linuxcontainers.org http://lists.linuxcontainers.org/listinfo/lxc-devel