[lxc-devel] [lxd/master] shared: Don't open files to get their mode

stgraber on Github lxc-bot at linuxcontainers.org
Wed Jul 17 16:53:35 UTC 2019


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 354 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20190717/53587539/attachment.bin>
-------------- next part --------------
From 495bcd3d08220712b2a81a5a1e7052f93a4385db Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Wed, 17 Jul 2019 12:53:10 -0400
Subject: [PATCH] shared: Don't open files to get their mode
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
 shared/util_linux.go | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)

diff --git a/shared/util_linux.go b/shared/util_linux.go
index 18d57938b0..323953b962 100644
--- a/shared/util_linux.go
+++ b/shared/util_linux.go
@@ -48,15 +48,9 @@ func GetFileStat(p string) (uid int, gid int, major int, minor int,
 	return
 }
 
-// FileCopy copies a file, overwriting the target if it exists.
+// GetPathMode returns a os.FileMode for the provided path
 func GetPathMode(path string) (os.FileMode, error) {
-	s, err := os.Open(path)
-	if err != nil {
-		return os.FileMode(0000), err
-	}
-	defer s.Close()
-
-	fi, err := s.Stat()
+	fi, err := os.Stat(path)
 	if err != nil {
 		return os.FileMode(0000), err
 	}


More information about the lxc-devel mailing list