Skip to content

Commit ee70cdd

Browse files
committed
Disable xattr APIs on MacOS
And add a CI run that covers it. Motivated by wanting to use this crate in bcvk. Signed-off-by: Colin Walters <[email protected]>
1 parent a73a0d7 commit ee70cdd

File tree

4 files changed

+24
-13
lines changed

4 files changed

+24
-13
lines changed

.github/workflows/rust.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,12 @@ jobs:
117117
run: cargo build --all-targets
118118
- name: cargo test
119119
run: cargo test --all-targets
120-
tests-windows:
121-
name: Tests, Windows
122-
runs-on: windows-latest
120+
build-and-test:
121+
name: Build and test on ${{ matrix.host }}
122+
runs-on: ${{ matrix.host }}
123+
strategy:
124+
matrix:
125+
host: [windows-latest, macos-latest]
123126
steps:
124127
- name: Check out repository
125128
uses: actions/checkout@v5

src/dirext.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -244,16 +244,16 @@ pub trait CapStdExtDirExt {
244244
/// to determine, and `None` will be returned in those cases.
245245
fn is_mountpoint(&self, path: impl AsRef<Path>) -> Result<Option<bool>>;
246246

247-
#[cfg(not(windows))]
247+
#[cfg(any(target_os = "android", target_os = "linux"))]
248248
/// Get the value of an extended attribute. If the attribute is not present,
249249
/// this function will return `Ok(None)`.
250250
fn getxattr(&self, path: impl AsRef<Path>, key: impl AsRef<OsStr>) -> Result<Option<Vec<u8>>>;
251251

252-
#[cfg(not(windows))]
252+
#[cfg(any(target_os = "android", target_os = "linux"))]
253253
/// List all extended attribute keys for this path.
254254
fn listxattrs(&self, path: impl AsRef<Path>) -> Result<crate::XattrList>;
255255

256-
#[cfg(not(windows))]
256+
#[cfg(any(target_os = "android", target_os = "linux"))]
257257
/// Set the value of an extended attribute.
258258
fn setxattr(
259259
&self,
@@ -614,6 +614,10 @@ where
614614

615615
// Ensure that the target path isn't absolute, and doesn't
616616
// have any parent references.
617+
#[cfg_attr(
618+
not(any(target_os = "android", target_os = "linux", test)),
619+
allow(dead_code)
620+
)]
617621
pub(crate) fn validate_relpath_no_uplinks(path: &Path) -> Result<&Path> {
618622
let is_absolute = path.is_absolute();
619623
let contains_uplinks = path
@@ -828,17 +832,17 @@ impl CapStdExtDirExt for Dir {
828832
is_mountpoint_impl_statx(self, path.as_ref()).map_err(Into::into)
829833
}
830834

831-
#[cfg(not(windows))]
835+
#[cfg(any(target_os = "android", target_os = "linux"))]
832836
fn getxattr(&self, path: impl AsRef<Path>, key: impl AsRef<OsStr>) -> Result<Option<Vec<u8>>> {
833837
crate::xattrs::impl_getxattr(self, path.as_ref(), key.as_ref())
834838
}
835839

836-
#[cfg(not(windows))]
840+
#[cfg(any(target_os = "android", target_os = "linux"))]
837841
fn listxattrs(&self, path: impl AsRef<Path>) -> Result<crate::XattrList> {
838842
crate::xattrs::impl_listxattrs(self, path.as_ref())
839843
}
840844

841-
#[cfg(not(windows))]
845+
#[cfg(any(target_os = "android", target_os = "linux"))]
842846
fn setxattr(
843847
&self,
844848
path: impl AsRef<Path>,

src/lib.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,16 @@ pub mod dirext;
2222
mod rootdir;
2323
#[cfg(any(target_os = "android", target_os = "linux"))]
2424
pub use rootdir::*;
25-
#[cfg(not(windows))]
25+
#[cfg(any(target_os = "android", target_os = "linux"))]
2626
mod xattrs;
27-
#[cfg(not(windows))]
27+
#[cfg(any(target_os = "android", target_os = "linux"))]
2828
pub use xattrs::XattrList;
2929

3030
#[cold]
31+
#[cfg_attr(
32+
not(any(target_os = "android", target_os = "linux", test)),
33+
allow(dead_code)
34+
)]
3135
pub(crate) fn escape_attempt() -> io::Error {
3236
io::Error::new(
3337
io::ErrorKind::PermissionDenied,

tests/it/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -718,7 +718,7 @@ fn test_walk_noxdev() -> Result<()> {
718718
}
719719

720720
#[test]
721-
#[cfg(not(windows))]
721+
#[cfg(any(target_os = "android", target_os = "linux"))]
722722
fn test_xattrs() -> Result<()> {
723723
use std::os::unix::ffi::OsStrExt;
724724

@@ -779,7 +779,7 @@ fn test_xattrs() -> Result<()> {
779779
}
780780

781781
#[test]
782-
#[cfg(not(windows))]
782+
#[cfg(any(target_os = "android", target_os = "linux"))]
783783
fn test_big_xattr() -> Result<()> {
784784
let td = &cap_tempfile::TempDir::new(cap_std::ambient_authority())?;
785785

0 commit comments

Comments
 (0)