xattr

package module
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2019 License: BSD-2-Clause Imports: 2 Imported by: 174

README

GoDoc Go Report Card Build Status Version Codecov

xattr

Extended attribute support for Go (linux + darwin + freebsd + netbsd).

"Extended attributes are name:value pairs associated permanently with files and directories, similar to the environment strings associated with a process. An attribute may be defined or undefined. If it is defined, its value may be empty or non-empty." See more...

SetWithFlags allows to additionally pass system flags to be forwarded to the underlying calls. FreeBSD and NetBSD do not support this and the parameter will be ignored.

The L variants of all functions (LGet/LSet/...) are identical to Get/Set/... except that they do not reference a symlink that appears at the end of a path. See GoDoc for details.

Example
  const path = "/tmp/myfile"
  const prefix = "user."

  if err := xattr.Set(path, prefix+"test", []byte("test-attr-value")); err != nil {
  	log.Fatal(err)
  }

  var list []string
  if list, err = xattr.List(path); err != nil {
  	log.Fatal(err)
  }

  var data []byte
  if data, err = xattr.Get(path, prefix+"test"); err != nil {
  	log.Fatal(err)
  }

  if err = xattr.Remove(path, prefix+"test"); err != nil {
  	log.Fatal(err)
  }

  // One can also specify the flags parameter to be passed to the OS.
  if err := xattr.SetWithFlags(path, prefix+"test", []byte("test-attr-value"), xattr.XATTR_CREATE); err != nil {
  	log.Fatal(err)
  }

Documentation

Overview

Package xattr provides support for extended attributes on linux, darwin and freebsd. Extended attributes are name:value pairs associated permanently with files and directories, similar to the environment strings associated with a process. An attribute may be defined or undefined. If it is defined, its value may be empty or non-empty. More details you can find here: https://en.wikipedia.org/wiki/Extended_file_attributes .

All functions are provided in triples: Get/LGet/FGet, Set/LSet/FSet etc. The "L" variant will not follow a symlink at the end of the path, and "F" variant accepts a file descriptor instead of a path.

Example for "L" variant, assuming path is "/symlink1/symlink2", where both components are symlinks: Get will follow "symlink1" and "symlink2" and operate on the target of "symlink2". LGet will follow "symlink1" but operate directly on "symlink2".

Index

Constants

View Source
const (
	XATTR_CREATE  = unix.XATTR_CREATE
	XATTR_REPLACE = unix.XATTR_REPLACE

	// ENOATTR is not exported by the syscall package on Linux, because it is
	// an alias for ENODATA. We export it here so it is available on all
	// our supported platforms.
	ENOATTR = syscall.ENODATA
)

Variables

This section is empty.

Functions

func FGet added in v0.4.0

func FGet(f *os.File, name string) ([]byte, error)

FGet is like Get but accepts a os.File instead of a file path.

func FList added in v0.4.0

func FList(f *os.File) ([]string, error)

FList is like List but accepts a os.File instead of a file path.

func FRemove added in v0.4.0

func FRemove(f *os.File, name string) error

FRemove is like Remove but accepts a os.File instead of a file path.

func FSet added in v0.4.0

func FSet(f *os.File, name string, data []byte) error

FSet is like Set but accepts a os.File instead of a file path.

func FSetWithFlags added in v0.4.0

func FSetWithFlags(f *os.File, name string, data []byte, flags int) error

FSetWithFlags is like SetWithFlags but accepts a os.File instead of a file path.

func Get added in v0.2.0

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

Get retrieves extended attribute data associated with path. It will follow all symlinks along the path.

func LGet added in v0.3.0

func LGet(path, name string) ([]byte, error)

LGet is like Get but does not follow a symlink at the end of the path.

func LList added in v0.3.0

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

LList is like List but does not follow a symlink at the end of the path.

func LRemove added in v0.3.0

func LRemove(path, name string) error

LRemove is like Remove but does not follow a symlink at the end of the path.

func LSet added in v0.3.0

func LSet(path, name string, data []byte) error

LSet is like Set but does not follow a symlink at the end of the path.

func LSetWithFlags added in v0.3.0

func LSetWithFlags(path, name string, data []byte, flags int) error

LSetWithFlags is like SetWithFlags but does not follow a symlink at the end of the path.

func List added in v0.2.0

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

List retrieves a list of names of extended attributes associated with the given path in the file system.

func Remove added in v0.2.0

func Remove(path, name string) error

Remove removes the attribute associated with the given path.

func Set added in v0.2.0

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

Set associates name and data together as an attribute of path.

func SetWithFlags added in v0.3.0

func SetWithFlags(path, name string, data []byte, flags int) error

SetWithFlags associates name and data together as an attribute of path. Forwards the flags parameter to the syscall layer.

Types

type Error added in v0.2.0

type Error struct {
	Op   string
	Path string
	Name string
	Err  error
}

Error records an error and the operation, file path and attribute that caused it.

func (*Error) Error added in v0.2.0

func (e *Error) Error() string

Jump to

Keyboard shortcuts

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