2017-07-23 12:24:45 +00:00
[![GoDoc ](https://godoc.org/github.com/pkg/xattr?status.svg )](http://godoc.org/github.com/pkg/xattr)
[![Go Report Card ](https://goreportcard.com/badge/github.com/pkg/xattr )](https://goreportcard.com/report/github.com/pkg/xattr)
[![Build Status ](https://travis-ci.org/pkg/xattr.svg?branch=master )](https://travis-ci.org/pkg/xattr)
2018-08-01 17:43:44 +00:00
[![Version ](https://badge.fury.io/gh/pkg%2Fxattr.svg )](https://github.com/pkg/xattr/releases)
2019-01-27 20:07:57 +00:00
[![Codecov ](https://codecov.io/gh/pkg/xattr/branch/master/graph/badge.svg )](https://codecov.io/gh/pkg/xattr)
2017-07-23 12:24:45 +00:00
xattr
=====
2019-04-24 10:32:52 +00:00
Extended attribute support for Go (linux + darwin + freebsd + netbsd).
2017-07-23 12:24:45 +00:00
"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... ](https://en.wikipedia.org/wiki/Extended_file_attributes )
2019-04-24 10:32:52 +00:00
`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.
2018-08-01 17:43:44 +00:00
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 ](http://godoc.org/github.com/pkg/xattr ) for details.
2017-07-23 12:24:45 +00:00
### Example
2018-03-30 10:38:37 +00:00
```go
2017-07-23 12:24:45 +00:00
const path = "/tmp/myfile"
const prefix = "user."
if err := xattr.Set(path, prefix+"test", []byte("test-attr-value")); err != nil {
log.Fatal(err)
}
2019-01-27 20:07:57 +00:00
2017-07-23 12:24:45 +00:00
var list []string
if list, err = xattr.List(path); err != nil {
log.Fatal(err)
}
2019-01-27 20:07:57 +00:00
2017-07-23 12:24:45 +00:00
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)
}
2018-08-01 17:43:44 +00:00
// 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)
}
2017-07-23 12:24:45 +00:00
```