File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -6,19 +6,28 @@ import "golang.org/x/sys/unix"
66// and associated with the given path in the file system.
77// It will returns a nil slice and nil error if the xattr is not set.
88func Lgetxattr (path string , attr string ) ([]byte , error ) {
9+ // Start with a 128 length byte array
910 dest := make ([]byte , 128 )
1011 sz , errno := unix .Lgetxattr (path , attr , dest )
11- if errno == unix .ENODATA {
12+
13+ switch {
14+ case errno == unix .ENODATA :
1215 return nil , nil
13- }
14- if errno == unix .ERANGE {
16+ case errno == unix .ERANGE :
17+ // 128 byte array might just not be good enough. A dummy buffer is used
18+ // to get the real size of the xattrs on disk
19+ sz , errno = unix .Lgetxattr (path , attr , []byte {})
20+ if errno != nil {
21+ return nil , errno
22+ }
1523 dest = make ([]byte , sz )
1624 sz , errno = unix .Lgetxattr (path , attr , dest )
17- }
18- if errno != nil {
25+ if errno != nil {
26+ return nil , errno
27+ }
28+ case errno != nil :
1929 return nil , errno
2030 }
21-
2231 return dest [:sz ], nil
2332}
2433
You can’t perform that action at this time.
0 commit comments