Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
Signed-off-by: Hiroyuki Moriya <41197469+Gekko0114@users.noreply.github.com>
  • Loading branch information
Gekko0114 committed Sep 29, 2024
1 parent df77c11 commit b930ae1
Showing 1 changed file with 24 additions and 40 deletions.
64 changes: 24 additions & 40 deletions experiment/selinux/src/tools/xattr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,55 +34,39 @@ where
// set_xattr sets extended attributes on a file specified by its path.
fn set_xattr(&self, attr: &str, data: &[u8]) -> Result<(), XattrError> {
let path = self.as_ref();
match path.get_xattr(attr) {
Ok(_) => match rfs::setxattr(path, attr, data, rfs::XattrFlags::REPLACE) {
Ok(_) => Ok(()),
Err(e) => {
let errno = e.raw_os_error();
if errno == libc::EINTR {
return Err(XattrError::EINTR(errno));
}
Err(XattrError::SetXattr(e.to_string()))
}
},
Err(_) => match rfs::setxattr(path, attr, data, rfs::XattrFlags::CREATE) {
Ok(_) => Ok(()),
Err(e) => {
let errno = e.raw_os_error();
if errno == libc::EINTR {
return Err(XattrError::EINTR(errno));
}
Err(XattrError::SetXattr(e.to_string()))
let op = match path.get_xattr(attr) {
Ok(_) => rfs::XattrFlags::REPLACE,
Err(_) => rfs::XattrFlags::CREATE,
};
match rfs::setxattr(path, attr, data, op) {
Ok(_) => Ok(()),
Err(e) => {
let errno = e.raw_os_error();
if errno == libc::EINTR {
return Err(XattrError::EINTR(errno));
}
},
Err(XattrError::SetXattr(e.to_string()))
}
}
}

// function similar with lsetxattr in golang.org/x/sys/unix repo.
// lset_xattr sets extended attributes on a symbolic link.
fn lset_xattr(&self, attr: &str, data: &[u8]) -> Result<(), XattrError> {
let path = self.as_ref();
match path.lget_xattr(attr) {
Ok(_) => match rfs::lsetxattr(path, attr, data, rfs::XattrFlags::REPLACE) {
Ok(_) => Ok(()),
Err(e) => {
let errno = e.raw_os_error();
if errno == libc::EINTR {
return Err(XattrError::EINTR(errno));
}
Err(XattrError::LSetXattr(e.to_string()))
}
},
Err(_) => match rfs::lsetxattr(path, attr, data, rfs::XattrFlags::CREATE) {
Ok(_) => Ok(()),
Err(e) => {
let errno = e.raw_os_error();
if errno == libc::EINTR {
return Err(XattrError::EINTR(errno));
}
Err(XattrError::LSetXattr(e.to_string()))
let op = match path.lget_xattr(attr) {
Ok(_) => rfs::XattrFlags::REPLACE,
Err(_) => rfs::XattrFlags::CREATE,
};
match rfs::lsetxattr(path, attr, data, op) {
Ok(_) => Ok(()),
Err(e) => {
let errno = e.raw_os_error();
if errno == libc::EINTR {
return Err(XattrError::EINTR(errno));
}
},
Err(XattrError::LSetXattr(e.to_string()))
}
}
}

Expand Down

0 comments on commit b930ae1

Please sign in to comment.