Browse Source

unix: simplify error handling in *listxattr on FreeBSD

The var e error declaration is shadowed inside the for loop, so the
outer e always stays nil. Also, there is no need to reset the inner e in
case of EPERM, as it is reset by ExattrList* on the next iteration
anyhow.

Change-Id: Ib395e34b5a390a5d37bee334c44f6f87d3add2a0
Reviewed-on: https://go-review.googlesource.com/85295
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Tobias Klauser 8 years ago
parent
commit
83801418e1
1 changed files with 3 additions and 9 deletions
  1. 3 9
      unix/syscall_freebsd.go

+ 3 - 9
unix/syscall_freebsd.go

@@ -293,7 +293,6 @@ func Listxattr(file string, dest []byte) (sz int, err error) {
 
 	// FreeBSD won't allow you to list xattrs from multiple namespaces
 	s := 0
-	var e error
 	for _, nsid := range [...]int{EXTATTR_NAMESPACE_USER, EXTATTR_NAMESPACE_SYSTEM} {
 		stmp, e := ExtattrListFile(file, nsid, uintptr(d), destsiz)
 
@@ -305,7 +304,6 @@ func Listxattr(file string, dest []byte) (sz int, err error) {
 		 * we don't have read permissions on, so don't ignore those errors
 		 */
 		if e != nil && e == EPERM && nsid != EXTATTR_NAMESPACE_USER {
-			e = nil
 			continue
 		} else if e != nil {
 			return s, e
@@ -319,7 +317,7 @@ func Listxattr(file string, dest []byte) (sz int, err error) {
 		d = initxattrdest(dest, s)
 	}
 
-	return s, e
+	return s, nil
 }
 
 func Flistxattr(fd int, dest []byte) (sz int, err error) {
@@ -327,11 +325,9 @@ func Flistxattr(fd int, dest []byte) (sz int, err error) {
 	destsiz := len(dest)
 
 	s := 0
-	var e error
 	for _, nsid := range [...]int{EXTATTR_NAMESPACE_USER, EXTATTR_NAMESPACE_SYSTEM} {
 		stmp, e := ExtattrListFd(fd, nsid, uintptr(d), destsiz)
 		if e != nil && e == EPERM && nsid != EXTATTR_NAMESPACE_USER {
-			e = nil
 			continue
 		} else if e != nil {
 			return s, e
@@ -345,7 +341,7 @@ func Flistxattr(fd int, dest []byte) (sz int, err error) {
 		d = initxattrdest(dest, s)
 	}
 
-	return s, e
+	return s, nil
 }
 
 func Llistxattr(link string, dest []byte) (sz int, err error) {
@@ -353,11 +349,9 @@ func Llistxattr(link string, dest []byte) (sz int, err error) {
 	destsiz := len(dest)
 
 	s := 0
-	var e error
 	for _, nsid := range [...]int{EXTATTR_NAMESPACE_USER, EXTATTR_NAMESPACE_SYSTEM} {
 		stmp, e := ExtattrListLink(link, nsid, uintptr(d), destsiz)
 		if e != nil && e == EPERM && nsid != EXTATTR_NAMESPACE_USER {
-			e = nil
 			continue
 		} else if e != nil {
 			return s, e
@@ -371,7 +365,7 @@ func Llistxattr(link string, dest []byte) (sz int, err error) {
 		d = initxattrdest(dest, s)
 	}
 
-	return s, e
+	return s, nil
 }
 
 //sys   ioctl(fd int, req uint, arg uintptr) (err error)