xattr

package module
v1.1.2-0...-1a54165 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 14, 2014 License: BSD-2-Clause Imports: 2 Imported by: 3

README

xattr

Package xattr provides a simple interface to user extended attributes on Linux and OSX.

Install it: go get github.com/ivaxer/go-xattr

Documentation is available on godoc.org.

License: Simplified BSD License (see LICENSE).

Documentation

Overview

Package xattr provides a simple interface to user extended attributes on Linux and OSX. Support for xattrs is filesystem dependant, so not a given even if you are running one of those operating systems.

On Linux you have to edit /etc/fstab to include "user_xattr". Also, on Linux user's extended attributes have a manditory prefix of "user.".

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Get

func Get(path, attr string) ([]byte, error)

Get retrieves extended attribute data associated with path. If there is an error, it will be of type *os.PathError.

See Getxattr for low-level usage.

func Getxattr

func Getxattr(path, attr string, dest []byte) (sz int, err error)

Getxattr retrieves value of the extended attribute identified by attr associated with given path in filesystem into buffer dest.

On success, dest contains data associated with attr, retrieved value size sz and nil error are returned.

On error, non-nil error is returned. Getxattr returns error if dest was too small for attribute value.

A nil slice can be passed as dest to get current size of attribute value, which can be used to estimate dest length for value associated with attr.

See getxattr(2) for more information.

Get is high-level function on top of Getxattr. Getxattr more efficient, because it issues one syscall per call, doesn't allocate memory for attribute data (caller can reuse buffer).

func IsNotExist

func IsNotExist(err error) bool

IsNotExist returns a boolean indicating whether the error is known to report that an extended attribute does not exist.

func List

func List(path string) ([]string, error)

List retrieves a list of names of extended attributes associated with path. If there is an error, it will be of type *os.PathError.

See Listxattr for low-level usage.

func Listxattr

func Listxattr(path string, dest []byte) (sz int, err error)

Listxattr retrieves the list of extended attribute names associated with path. The list is set of NULL-terminated names.

On success, dest containes list of NULL-terminated names, the length of the extended attribute list and nil error are returned.

On error, non nil error is returned. Listxattr returns error if dest buffer was too small for extended attribute list.

The list of names is returned as an unordered array of NULL-terminated character strings (attribute names are separated by NULL characters), like this:

user.name1\0system.name1\0user.name2\0

A nil slice can be passed as dest to get the current size of the list of extended attribute names, which can be used to estimate dest length for the list of names.

See listxattr(2) for more information.

List is high-level function on top of Listxattr.

func Remove

func Remove(path, attr string) error

Remove removes the extended attribute. If there is an error, it will be of type *os.PathError.

func Removexattr

func Removexattr(path, attr string) error

Removexattr removes the extended attribute attr accosiated with path.

On error, non-nil error is returned.

See removexattr(2) for more information.

func Set

func Set(path, attr string, data []byte) error

Set associates data as an extended attribute of path. If there is an error, it will be of type *os.PathError.

See Setxattr for low-level usage.

func Setxattr

func Setxattr(path, attr string, data []byte, flags int) error

Setxattr sets value in data of extended attribute attr and accosiated with path.

The flags refine the semantic of the operation. XATTR_CREATE specifies pure create, which fails if attr already exists. XATTR_REPLACE specifies a pure replace operation, which fails if the attr does not already exist. By default (no flags), the attr will be created if need be, or will simply replace the value if attr exists.

On error, non nil error is returned.

See setxattr(2) for more information.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL