pxar: change logic and impl all command line flags for xattrs/fcaps/acls

Allows to individually set the flags for storing/dumping/restoring of
xattrs/fcaps/acls in the cli of pxar.
Changes logic so that each of them can be threated individually.

Signed-off-by: Christian Ebner <c.ebner@proxmox.com>
This commit is contained in:
Christian Ebner
2019-05-28 11:16:21 +02:00
committed by Dietmar Maurer
parent 60e589a111
commit 9b38443314
3 changed files with 88 additions and 21 deletions

View File

@ -220,16 +220,22 @@ impl <'a, W: Write> Encoder<'a, W> {
Ok(())
}
/// True if all of the given feature flags are set in the Encoder, false otherwise
fn has_features(&self, feature_flags: u64) -> bool {
(self.feature_flags & feature_flags) == feature_flags
}
/// True if at least one of the given feature flags is set in the Encoder, false otherwise
fn has_some_features(&self, feature_flags: u64) -> bool {
(self.feature_flags & feature_flags) != 0
}
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) {
if !self.has_some_features(flags) {
return Ok((xattrs, fcaps));
}
// Should never be called on symlinks, just in case check anyway
@ -260,11 +266,13 @@ impl <'a, W: Write> Encoder<'a, W> {
};
if xattr::is_security_capability(&name) {
// fcaps are stored in own format within the archive
fcaps = Some(CaFormatFCaps {
data: value,
});
} else {
if self.has_features(CA_FORMAT_WITH_FCAPS) {
// fcaps are stored in own format within the archive
fcaps = Some(CaFormatFCaps {
data: value,
});
}
} else if self.has_features(CA_FORMAT_WITH_XATTRS) {
xattrs.push(CaFormatXAttr {
name: name.to_vec(),
value: value,