Minor refactoring of pxars xattr encoder/decoder, mostly reformatting and renaming.
Signed-off-by: Christian Ebner <c.ebner@proxmox.com>
This commit is contained in:
committed by
Dietmar Maurer
parent
c05a8c8d18
commit
357e4614e2
@ -230,25 +230,29 @@ impl <'a, W: Write> Encoder<'a, W> {
|
||||
(self.feature_flags & feature_flags) == feature_flags
|
||||
}
|
||||
|
||||
fn read_xattrs(&self, fd: RawFd, stat: &FileStat, entry: &CaFormatEntry) -> Result<(Vec<CaFormatXAttr>, Option<CaFormatFCaps>), Error> {
|
||||
fn read_xattrs(&self, fd: RawFd, stat: &FileStat) -> Result<(Vec<CaFormatXAttr>, Option<CaFormatFCaps>), Error> {
|
||||
let mut xattrs = Vec::new();
|
||||
let mut fcaps = None;
|
||||
|
||||
let flags = CA_FORMAT_WITH_XATTRS | CA_FORMAT_WITH_FCAPS;
|
||||
if !self.has_features(flags) { return Ok((xattrs, fcaps)); }
|
||||
if !self.has_features(flags) {
|
||||
return Ok((xattrs, fcaps));
|
||||
}
|
||||
// Should never be called on symlinks, just in case check anyway
|
||||
if (stat.st_mode & libc::S_IFMT) == libc::S_IFLNK { return Ok((xattrs, fcaps)); }
|
||||
if (stat.st_mode & libc::S_IFMT) == libc::S_IFLNK {
|
||||
return Ok((xattrs, fcaps));
|
||||
}
|
||||
|
||||
let xattr_names = match xattr::flistxattr(fd) {
|
||||
Ok(names) => names,
|
||||
Err(Errno::EOPNOTSUPP) => return Ok((xattrs, fcaps)),
|
||||
Err(Errno::EBADF) => return Ok((xattrs, fcaps)),
|
||||
Err(err) => bail!("read_xattrs failed for {:?} - {}", self.full_path(), err),
|
||||
};
|
||||
|
||||
for name in xattr_names.split(|c| *c == '\0' as u8) {
|
||||
for name in xattr_names.split(|c| *c == b'\0') {
|
||||
// Only extract the relevant extended attributes
|
||||
if !xattr::name_store(&name) { continue; }
|
||||
if !xattr::is_valid_xattr_name(&name) {
|
||||
continue;
|
||||
}
|
||||
|
||||
let value = match xattr::fgetxattr(fd, name) {
|
||||
Ok(value) => value,
|
||||
@ -257,7 +261,7 @@ impl <'a, W: Write> Encoder<'a, W> {
|
||||
Err(err) => bail!("read_xattrs failed for {:?} - {}", self.full_path(), err),
|
||||
};
|
||||
|
||||
if xattr::security_capability(&name) {
|
||||
if xattr::is_security_capability(&name) {
|
||||
// fcaps are stored in own format within the archive
|
||||
fcaps = Some(CaFormatFCaps {
|
||||
data: value,
|
||||
@ -355,10 +359,12 @@ impl <'a, W: Write> Encoder<'a, W> {
|
||||
|
||||
self.read_chattr(rawfd, &mut dir_entry)?;
|
||||
self.read_fat_attr(rawfd, magic, &mut dir_entry)?;
|
||||
let (xattrs, fcaps) = self.read_xattrs(rawfd, &dir_stat, &dir_entry)?;
|
||||
let (xattrs, fcaps) = self.read_xattrs(rawfd, &dir_stat)?;
|
||||
|
||||
self.write_entry(dir_entry)?;
|
||||
for xattr in xattrs { self.write_xattr(xattr)?; }
|
||||
for xattr in xattrs {
|
||||
self.write_xattr(xattr)?;
|
||||
}
|
||||
self.write_fcaps(fcaps)?;
|
||||
|
||||
let mut dir_count = 0;
|
||||
@ -545,10 +551,12 @@ impl <'a, W: Write> Encoder<'a, W> {
|
||||
|
||||
self.read_chattr(filefd, &mut entry)?;
|
||||
self.read_fat_attr(filefd, magic, &mut entry)?;
|
||||
let (xattrs, fcaps) = self.read_xattrs(filefd, &stat, &entry)?;
|
||||
let (xattrs, fcaps) = self.read_xattrs(filefd, &stat)?;
|
||||
|
||||
self.write_entry(entry)?;
|
||||
for xattr in xattrs { self.write_xattr(xattr)?; }
|
||||
for xattr in xattrs {
|
||||
self.write_xattr(xattr)?;
|
||||
}
|
||||
self.write_fcaps(fcaps)?;
|
||||
|
||||
let include_payload;
|
||||
|
Reference in New Issue
Block a user