[lxc-devel] [lxd/master] xattr: Support empty values

stgraber on Github lxc-bot at linuxcontainers.org
Thu May 3 08:40:06 UTC 2018


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/20180503/483ef983/attachment.bin>
-------------- next part --------------
From a1783b173cb370600006ddb8cacbcbad3ee02259 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Thu, 3 May 2018 10:38:45 +0200
Subject: [PATCH] xattr: Support empty values
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>
---
 lxd/container_lxc.go      |  8 ++++----
 shared/util_linux.go      | 13 +++++++------
 shared/util_linux_test.go |  1 +
 3 files changed, 12 insertions(+), 10 deletions(-)

diff --git a/lxd/container_lxc.go b/lxd/container_lxc.go
index c1d7845b1..26376e62e 100644
--- a/lxd/container_lxc.go
+++ b/lxd/container_lxc.go
@@ -5961,23 +5961,23 @@ func (c *containerLXC) tarStoreFile(linkmap map[uint64]string, offset int, tw *t
 	if link == "" {
 		hdr.Xattrs, err = shared.GetAllXattr(path)
 		if err != nil {
-			return fmt.Errorf("failed to read xattr: %s", err)
+			return fmt.Errorf("Failed to read xattr for '%s': %s", path, err)
 		}
 	}
 
 	if err := tw.WriteHeader(hdr); err != nil {
-		return fmt.Errorf("failed to write tar header: %s", err)
+		return fmt.Errorf("Failed to write tar header: %s", err)
 	}
 
 	if hdr.Typeflag == tar.TypeReg {
 		f, err := os.Open(path)
 		if err != nil {
-			return fmt.Errorf("failed to open the file: %s", err)
+			return fmt.Errorf("Failed to open the file: %s", err)
 		}
 		defer f.Close()
 
 		if _, err := io.Copy(tw, f); err != nil {
-			return fmt.Errorf("failed to copy file content: %s", err)
+			return fmt.Errorf("Failed to copy file content: %s", err)
 		}
 	}
 
diff --git a/shared/util_linux.go b/shared/util_linux.go
index e0d0056d8..b6d83794f 100644
--- a/shared/util_linux.go
+++ b/shared/util_linux.go
@@ -473,15 +473,16 @@ func GetAllXattr(path string) (xattrs map[string]string, err error) {
 		if err != nil || pre < 0 {
 			return nil, err
 		}
-		if pre == 0 {
-			return nil, fmt.Errorf("No valid extended attribute value found.")
-		}
 
 		dest = make([]byte, pre)
-		post, err = syscall.Getxattr(path, xattr, dest)
-		if err != nil || post < 0 {
-			return nil, err
+		post := 0
+		if pre > 0 {
+			post, err = syscall.Getxattr(path, xattr, dest)
+			if err != nil || post < 0 {
+				return nil, err
+			}
 		}
+
 		if post != pre {
 			return nil, e1
 		}
diff --git a/shared/util_linux_test.go b/shared/util_linux_test.go
index 36e20e879..bd54fae4b 100644
--- a/shared/util_linux_test.go
+++ b/shared/util_linux_test.go
@@ -13,6 +13,7 @@ func TestGetAllXattr(t *testing.T) {
 		testxattr = map[string]string{
 			"user.checksum": "asdfsf13434qwf1324",
 			"user.random":   "This is a test",
+			"user.empty":    "",
 		}
 	)
 	xattrFile, err := ioutil.TempFile("", "")


More information about the lxc-devel mailing list