Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

xattr.Getxattr always returns empty string #1

Open
bitcartel opened this issue Apr 10, 2012 · 11 comments
Open

xattr.Getxattr always returns empty string #1

bitcartel opened this issue Apr 10, 2012 · 11 comments

Comments

@bitcartel
Copy link

Hi,

Using Mac OS X 10.7.3 and Go 1

From the example and my own tests, both writing and deleting a key-value pair succeeds (confirmed with /usr/bin/xattr).

However, Getxattr always returns an empty value.

value, _ := xattr.Getxattr(file, name)

Thanks.

@davecheney
Copy link
Owner

You are consuming the error, can you please try again and print the error if not nil, it may give us a clue what is going on.

On 10/04/2012, at 14:08, bitcartelreply@reply.github.com wrote:

Hi,

Using Mac OS X 10.7.3 and Go 1

From the example and my own tests, both writing and deleting a key-value pair succeeds (confirmed with /usr/bin/xattr).

However, Getxattr always returns an empty value.

value, _ := xattr.Getxattr(file, name)

Thanks.


Reply to this email directly or view it on GitHub:
#1

@bitcartel
Copy link
Author

value, myerr := xattr.Getxattr(file, name)
fmt.Printf("value = %s\n", value)
fmt.Printf("err = %s\n",myerr)

results in:

value =
err = getxattr testfile username: errno 0

On 4/9/12 9:14 PM, Dave Cheney wrote:

You are consuming the error, can you please try again and print the error if not nil, it may give us a clue what is going on.

On 10/04/2012, at 14:08, bitcartelreply@reply.github.com wrote:

Hi,

Using Mac OS X 10.7.3 and Go 1

From the example and my own tests, both writing and deleting a key-value pair succeeds (confirmed with /usr/bin/xattr).

However, Getxattr always returns an empty value.

value, _ := xattr.Getxattr(file, name)

Thanks.


Reply to this email directly or view it on GitHub:
#1


Reply to this email directly or view it on GitHub:
#1 (comment)

@davecheney
Copy link
Owner

Thanks, I'll take a look this evening. For comparison could you post the output of xattr.

On 10/04/2012, at 14:43, bitcartelreply@reply.github.com wrote:

value, myerr := xattr.Getxattr(file, name)
fmt.Printf("value = %s\n", value)
fmt.Printf("err = %s\n",myerr)

results in:

value =
err = getxattr testfile username: errno 0

On 4/9/12 9:14 PM, Dave Cheney wrote:

You are consuming the error, can you please try again and print the error if not nil, it may give us a clue what is going on.

On 10/04/2012, at 14:08, bitcartelreply@reply.github.com wrote:

Hi,

Using Mac OS X 10.7.3 and Go 1

From the example and my own tests, both writing and deleting a key-value pair succeeds (confirmed with /usr/bin/xattr).

However, Getxattr always returns an empty value.

value, _ := xattr.Getxattr(file, name)

Thanks.


Reply to this email directly or view it on GitHub:
#1


Reply to this email directly or view it on GitHub:
#1 (comment)


Reply to this email directly or view it on GitHub:
#1 (comment)

@bitcartel
Copy link
Author

which xattr
/usr/bin/xattr

xattr -l testfile
username: dave

Thx.

On 4/9/12 9:54 PM, Dave Cheney wrote:

Thanks, I'll take a look this evening. For comparison could you post the output of xattr.

On 10/04/2012, at 14:43, bitcartelreply@reply.github.com wrote:

value, myerr := xattr.Getxattr(file, name)
fmt.Printf("value = %s\n", value)
fmt.Printf("err = %s\n",myerr)

results in:

value =
err = getxattr testfile username: errno 0

On 4/9/12 9:14 PM, Dave Cheney wrote:

You are consuming the error, can you please try again and print the error if not nil, it may give us a clue what is going on.

On 10/04/2012, at 14:08, bitcartelreply@reply.github.com wrote:

Hi,

Using Mac OS X 10.7.3 and Go 1

From the example and my own tests, both writing and deleting a key-value pair succeeds (confirmed with /usr/bin/xattr).

However, Getxattr always returns an empty value.

value, _ := xattr.Getxattr(file, name)

Thanks.


Reply to this email directly or view it on GitHub:
#1


Reply to this email directly or view it on GitHub:
#1 (comment)


Reply to this email directly or view it on GitHub:
#1 (comment)


Reply to this email directly or view it on GitHub:
#1 (comment)

@davecheney
Copy link
Owner

Hello, sorry I haven't replied yet, I hope to have some time to look at this issue on the weekend.

@bitcartel
Copy link
Author

That's cool, thanks.

On 4/12/12 5:49 AM, Dave Cheney wrote:

Hello, sorry I haven't replied yet, I hope to have some time to look at this issue on the weekend.


Reply to this email directly or view it on GitHub:
#1 (comment)

@kuba--
Copy link

kuba-- commented Jun 13, 2014

..to fix this issue for darwin (macosx), you just need to consume Errno(0) in syscall_darwin.go

func getxattr(path string, name string, value *byte, size int, pos int, options int) (r int, e error) {
    if r0, _, e1 := syscall.Syscall6(syscall.SYS_GETXATTR, uintptr(unsafe.Pointer(syscall.StringBytePtr(path))), uintptr(unsafe.Pointer(syscall.StringBytePtr(name))), uintptr(unsafe.Pointer(value)), uintptr(size), uintptr(pos), uintptr(options)); e1 != syscall.Errno(0) {
        e = e1
    } else {
        r = int(r0)
    }
    return
}

@loop0
Copy link

loop0 commented Mar 28, 2016

I can confirm @kuba-- answer. You have to check for e1 != syscall.Errno(0) before returning it as error. I can make a pull request to fix this.

@avg-I
Copy link

avg-I commented Aug 12, 2016

Nudge. As it is the code won't work on darwin.
And a relevant documentation link, just in case: https://golang.org/pkg/syscall/#Errno

@kuba--
Copy link

kuba-- commented Aug 12, 2016

@avg-I: two years ago I made some improvements in my repo: https://github.com/kuba--/xattr
and it works for me on darwin

@avg-I
Copy link

avg-I commented Aug 12, 2016

@kuba-- thank you for letting me know! I've created a pull request against your repo with a commit that adds freebsd support kuba--/xattr#1. The change should be applicable to this repo as well (modulo xattr_test.go).

gilbertchen pushed a commit to gilbertchen/xattr that referenced this issue Sep 26, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants