Skip to content

Commit 8b183b3

Browse files
committed
test: test listing more than 4096 bytes of extended attributes
fixes #84
1 parent df9ee49 commit 8b183b3

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

tests/main.rs

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::collections::BTreeSet;
22
use std::ffi::OsStr;
33
use xattr::FileExt;
44

5-
use tempfile::{tempfile, NamedTempFile};
5+
use tempfile::{tempfile, tempfile_in, NamedTempFile};
66

77
#[test]
88
#[cfg(any(
@@ -171,6 +171,37 @@ fn test_multi() {
171171
assert!(items.is_empty());
172172
}
173173

174+
// This test is skipped on android because the /data/tmp filesystem doesn't support >4kib of
175+
// extended attributes.
176+
#[test]
177+
#[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "macos"))]
178+
fn test_large() {
179+
use std::ffi::OsString;
180+
use std::os::unix::ffi::OsStrExt;
181+
// On Linux, this only works in tmpfs!
182+
let tmp = if cfg!(target_os = "linux") {
183+
tempfile_in("/dev/shm")
184+
} else {
185+
tempfile()
186+
}
187+
.unwrap();
188+
let mut items: BTreeSet<OsString> = (0..100)
189+
.map(|i| format!("user.test{i:0100}").into())
190+
.collect();
191+
192+
for it in &items {
193+
tmp.set_xattr(it, b"value").unwrap();
194+
}
195+
for it in tmp
196+
.list_xattr()
197+
.unwrap()
198+
.filter(|x| x.as_bytes().starts_with(b"user."))
199+
{
200+
assert!(items.remove(&*it));
201+
}
202+
assert!(items.is_empty());
203+
}
204+
174205
// Tests the deref API variants - regression test for
175206
// https://github.com/Stebalien/xattr/issues/57
176207
#[test]

0 commit comments

Comments
 (0)