[lxc-devel] [lxd/master] Fix lxc file on Windows

stgraber on Github lxc-bot at linuxcontainers.org
Mon Feb 15 22:53:43 UTC 2016


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 370 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20160215/a9daf2ce/attachment.bin>
-------------- next part --------------
From 51a1a87b721bf31da1096b467f27d316cf860850 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Mon, 15 Feb 2016 17:30:54 -0500
Subject: [PATCH] Fix lxc file on Windows
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Closes #1607

Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
 lxc/file.go         | 16 ++++++++++------
 lxc/file_unix.go    | 21 +++++++++++++++++++++
 lxc/file_windows.go | 11 +++++++++++
 3 files changed, 42 insertions(+), 6 deletions(-)
 create mode 100644 lxc/file_unix.go
 create mode 100644 lxc/file_windows.go

diff --git a/lxc/file.go b/lxc/file.go
index 9a9676f..5b987a8 100644
--- a/lxc/file.go
+++ b/lxc/file.go
@@ -121,20 +121,24 @@ func (c *fileCmd) push(config *lxd.Config, args []string) error {
 		if targetfilename == "" {
 			fpath = path.Join(fpath, path.Base(f.Name()))
 		}
-		/* If not specified, preserve file permissions */
-		fInfo, err := f.Stat()
+
+		fMode, fUid, fGid, err := c.getOwner(f)
 		if err != nil {
 			return err
 		}
-		if c.mode == "" {
-			mode = fInfo.Mode()
+
+		if c.mode != "" {
+			mode = fMode
 		}
+
 		if c.uid == -1 {
-			uid = int(fInfo.Sys().(*syscall.Stat_t).Uid)
+			uid = fUid
 		}
+
 		if c.gid == -1 {
-			gid = int(fInfo.Sys().(*syscall.Stat_t).Gid)
+			gid = fGid
 		}
+
 		err = d.PushFile(container, fpath, gid, uid, mode, f)
 		if err != nil {
 			return err
diff --git a/lxc/file_unix.go b/lxc/file_unix.go
new file mode 100644
index 0000000..1cc6aba
--- /dev/null
+++ b/lxc/file_unix.go
@@ -0,0 +1,21 @@
+// +build !windows
+
+package main
+
+import (
+	"os"
+	"syscall"
+)
+
+func (c *fileCmd) getOwner(f *os.File) (os.FileMode, int, int, error) {
+	fInfo, err := f.Stat()
+	if err != nil {
+		return os.FileMode(0), -1, -1, err
+	}
+
+	mode := fInfo.Mode()
+	uid := int(fInfo.Sys().(*syscall.Stat_t).Uid)
+	gid := int(fInfo.Sys().(*syscall.Stat_t).Gid)
+
+	return mode, uid, gid, nil
+}
diff --git a/lxc/file_windows.go b/lxc/file_windows.go
new file mode 100644
index 0000000..c3bf927
--- /dev/null
+++ b/lxc/file_windows.go
@@ -0,0 +1,11 @@
+// +build windows
+
+package main
+
+import (
+	"os"
+)
+
+func (c *fileCmd) getOwner(f *os.File) (os.FileMode, int, int, error) {
+	return os.FileMode(0), -1, -1, nil
+}


More information about the lxc-devel mailing list