[lxc-devel] [lxd/master] only normalize paths on linux

tych0 on Github lxc-bot at linuxcontainers.org
Wed Oct 26 17:21:31 UTC 2016


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 429 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20161026/9bbd477e/attachment.bin>
-------------- next part --------------
From 8997c8458d402d312eb3e7f86d2fceafbde35892 Mon Sep 17 00:00:00 2001
From: Tycho Andersen <tycho.andersen at canonical.com>
Date: Wed, 26 Oct 2016 11:20:20 -0600
Subject: [PATCH] only normalize paths on linux

Prepending / on windows seems like a bad idea ;)

Closes #2565

Signed-off-by: Tycho Andersen <tycho.andersen at canonical.com>
---
 lxc/file.go         | 11 +----------
 lxc/file_unix.go    | 16 ++++++++++++++++
 lxc/file_windows.go |  4 ++++
 3 files changed, 21 insertions(+), 10 deletions(-)

diff --git a/lxc/file.go b/lxc/file.go
index f610f5f..82050a6 100644
--- a/lxc/file.go
+++ b/lxc/file.go
@@ -74,16 +74,7 @@ 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] + "/"
-	}
+	pathSpec[1] = c.normalize(pathSpec[1], target)
 
 	targetPath := pathSpec[1]
 	remote, container := config.ParseRemoteAndContainer(pathSpec[0])
diff --git a/lxc/file_unix.go b/lxc/file_unix.go
index 1cc6aba..ba70c45 100644
--- a/lxc/file_unix.go
+++ b/lxc/file_unix.go
@@ -4,6 +4,7 @@ package main
 
 import (
 	"os"
+	"path/filepath"
 	"syscall"
 )
 
@@ -19,3 +20,18 @@ func (c *fileCmd) getOwner(f *os.File) (os.FileMode, int, int, error) {
 
 	return mode, uid, gid, nil
 }
+
+func (c *fileCmd) normalize(path string, target string) string {
+	/* 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
+	 */
+	path = filepath.Clean("/" + path)
+	if target[len(target)-1] == '/' {
+		path = path + "/"
+	}
+
+	return path
+}
diff --git a/lxc/file_windows.go b/lxc/file_windows.go
index c3bf927..583a518 100644
--- a/lxc/file_windows.go
+++ b/lxc/file_windows.go
@@ -9,3 +9,7 @@ import (
 func (c *fileCmd) getOwner(f *os.File) (os.FileMode, int, int, error) {
 	return os.FileMode(0), -1, -1, nil
 }
+
+func (c *fileCmd) normalize(path string, target string) string {
+	return path
+}


More information about the lxc-devel mailing list