[lxc-devel] [lxd/master] shared: FileCopy should keep the same mode

tych0 on Github lxc-bot at linuxcontainers.org
Sat Feb 4 12:15:07 UTC 2017


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 361 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20170204/29b919d4/attachment.bin>
-------------- next part --------------
From ae99416627cbb08805859f33f6133f9335c0eee9 Mon Sep 17 00:00:00 2001
From: Tycho Andersen <tycho.andersen at canonical.com>
Date: Sat, 4 Feb 2017 13:13:26 +0100
Subject: [PATCH] shared: FileCopy should keep the same mode

Signed-off-by: Tycho Andersen <tycho.andersen at canonical.com>
---
 shared/util.go | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/shared/util.go b/shared/util.go
index 21c2b29..e563dcb 100644
--- a/shared/util.go
+++ b/shared/util.go
@@ -275,10 +275,15 @@ func FileCopy(source string, dest string) error {
 	}
 	defer s.Close()
 
+	fi, err := s.Stat()
+	if err != nil {
+		return err
+	}
+
 	d, err := os.Create(dest)
 	if err != nil {
 		if os.IsExist(err) {
-			d, err = os.OpenFile(dest, os.O_WRONLY, 0700)
+			d, err = os.OpenFile(dest, os.O_WRONLY, fi.Mode())
 			if err != nil {
 				return err
 			}


More information about the lxc-devel mailing list