Yet another Extended Attributes library for Rust.
xattr
?Extended Attributes syscalls vary across implementations, for example, to set an EA:
```c // Linux int setxattr(const char *path, const char *name, const void *value, size_t size, int flags);
// FreeBSD ssizet extattrsetfile(const char *path, int attrnamespace, const char *attrname, const void *data, sizet nbytes);
// macOS int setxattr(const char *path, const char *name, void *value, sizet size, uint32_t position, int options); ```
xattr
erases differences in those APIs and provides a consistent, rusty
interface.
rust
// A consistent API that would work on every OS
pub fn set<N, P>(path: P, name: N, value: &[u8]) -> Result<()>
extattr
aims to provide bindings close to the native one.
```rust // Linux pub fn setxattr
( path: P, name: S, value: B, flags: SetxattrFlag ) -> Result<()>
// FreeBSD pub fn extattrsetfile
( path: P, attrnamespace: AttrNamespace, attrname: S, data: B ) -> Result<()>
// macOS pub fn setxattr
( path: P, name: S, value: B, position: u32, options: Options ) -> Result<()> ```
In most cases, you would like to use xattr
instead of extattr
. However, if
you are on Linux and want to use that extra flags
argument, or you are on macOS
and want to use the arguments position
and options
, then extattr
probably
is a good choice:)
extattr
is supported on Rust 1.56.1 and higher. The MSRV will not be changed
without bumping the major version.
Contributions of all forms are welcome, feel free to file an issue or make a pull request!
Format the code
shell
$ cargo fmt
Pass the tests
shell
$ cargo test