[lxc-devel] [lxd/master] Fix random path stuff
tych0 on Github
lxc-bot at linuxcontainers.org
Tue Oct 25 21:08:34 UTC 2016
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 301 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20161025/76b9186b/attachment.bin>
-------------- next part --------------
From 6f0d82f7209a5ce4cd533d1dc4c2d7574d8a717a Mon Sep 17 00:00:00 2001
From: Tycho Andersen <tycho.andersen at 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.andersen at 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.andersen at 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.andersen at 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
}
More information about the lxc-devel
mailing list