Skip to content

Commit

Permalink
Merge pull request #29 from Stebalien/chore/cleanup
Browse files Browse the repository at this point in the history
- 2021 edition and friends
- build fixes
  • Loading branch information
Stebalien committed Nov 29, 2022
2 parents cb96edf + a60ad02 commit 6b67d6b
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 18 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
@@ -1,5 +1,6 @@
[package]
name = "xattr"
edition = "2021"
version = "0.2.3"
authors = ["Steven Allen <steven@stebalien.com>"]
description = "unix extended filesystem attributes"
Expand Down
5 changes: 2 additions & 3 deletions src/lib.rs
@@ -1,10 +1,11 @@
#![allow(clippy::comparison_chain)]
//! A pure-Rust library to manage extended attributes.
//!
//! It provides support for manipulating extended attributes
//! (`xattrs`) on modern Unix filesystems. See the `attr(5)`
//! manpage for more details.
//!
//! An extension trait [`FileExt`](::FileExt) is provided to directly work with
//! An extension trait [`FileExt`] is provided to directly work with
//! standard `File` objects and file descriptors.
//!
//! NOTE: In case of a symlink as path argument, all methods
Expand All @@ -25,8 +26,6 @@
//! }
//! ```

extern crate libc;

mod error;
mod sys;
mod util;
Expand Down
10 changes: 6 additions & 4 deletions src/sys/bsd.rs
Expand Up @@ -8,13 +8,15 @@ use std::os::unix::io::RawFd;
use std::path::Path;

use libc::{c_int, c_void, size_t, EPERM};
use util::{allocate_loop, path_to_c};

use libc::{extattr_delete_fd, extattr_get_fd, extattr_list_fd, extattr_set_fd,
extattr_delete_link, extattr_get_link, extattr_list_link, extattr_set_link,
EXTATTR_NAMESPACE_USER, EXTATTR_NAMESPACE_SYSTEM
use libc::{
extattr_delete_fd, extattr_delete_link, extattr_get_fd, extattr_get_link, extattr_list_fd,
extattr_list_link, extattr_set_fd, extattr_set_link, EXTATTR_NAMESPACE_SYSTEM,
EXTATTR_NAMESPACE_USER,
};

use crate::util::{allocate_loop, path_to_c};

const EXTATTR_NAMESPACE_USER_STRING: &'static str = "user";
const EXTATTR_NAMESPACE_SYSTEM_STRING: &'static str = "system";
const EXTATTR_NAMESPACE_NAMES: [&'static str; 3] = [
Expand Down
4 changes: 2 additions & 2 deletions src/sys/linux_macos/macos.rs
@@ -1,4 +1,4 @@
use libc::{c_char, c_int, c_void, size_t, ssize_t, uint32_t};
use libc::{c_char, c_int, c_void, size_t, ssize_t};

const XATTR_NOFOLLOW: c_int = 0x0001;

Expand Down Expand Up @@ -48,7 +48,7 @@ pub unsafe fn lsetxattr(
name: *const c_char,
value: *const c_void,
size: size_t,
) -> ssize_t {
) -> c_int {
use libc::setxattr;
setxattr(path, name, value, size, 0, XATTR_NOFOLLOW)
}
Expand Down
2 changes: 1 addition & 1 deletion src/sys/linux_macos/mod.rs
Expand Up @@ -19,7 +19,7 @@ use std::path::Path;

use libc::{c_char, c_void, size_t};

use util::{allocate_loop, name_to_c, path_to_c};
use crate::util::{allocate_loop, name_to_c, path_to_c};

/// An iterator over a set of extended attributes names.
pub struct XAttrs {
Expand Down
1 change: 1 addition & 0 deletions src/sys/mod.rs
Expand Up @@ -9,6 +9,7 @@ macro_rules! platforms {
pub use self::$module::*;

#[cfg(any($(target_os = $platform),*))]
#[allow(deprecated)] // other platforms still use ENOATTR
pub const ENOATTR: ::libc::c_int = ::libc::ENOATTR;
)*

Expand Down
2 changes: 1 addition & 1 deletion src/util.rs
Expand Up @@ -10,7 +10,7 @@ use libc::{ssize_t, ERANGE};
// Need to use this one as libc only defines this on supported platforms. Given
// that we want to at least compile on unsupported platforms, we define this in
// our platform-specific modules.
use sys::ENOATTR;
use crate::sys::ENOATTR;

#[allow(dead_code)]
pub fn name_to_c(name: &OsStr) -> io::Result<CString> {
Expand Down
13 changes: 6 additions & 7 deletions tests/main.rs
@@ -1,6 +1,3 @@
extern crate tempfile;
extern crate xattr;

use std::collections::BTreeSet;
use std::ffi::OsStr;
use xattr::FileExt;
Expand Down Expand Up @@ -98,14 +95,16 @@ fn test_multi() {
OsStr::new("user.test1"),
OsStr::new("user.test2"),
OsStr::new("user.test3"),
].iter()
.cloned()
.collect();
]
.iter()
.cloned()
.collect();

for it in &items {
tmp.set_xattr(it, b"value").unwrap();
}
for it in tmp.list_xattr()
for it in tmp
.list_xattr()
.unwrap()
.filter(|x| x.as_bytes().starts_with(&*b"user."))
{
Expand Down

0 comments on commit 6b67d6b

Please sign in to comment.