Importing extended attributes from tar files (re #1)

pull/10/head
Dennis Schwerdel 2017-04-13 15:32:37 +02:00
parent 3cb21cb59e
commit d4c0964815
1 changed files with 29 additions and 18 deletions

View File

@ -11,6 +11,7 @@ use tar;
fn inode_from_entry<R: Read>(entry: &mut tar::Entry<R>) -> Result<Inode, RepositoryError> {
let mut inode = {
let path = try!(entry.path());
let header = entry.header();
let file_type = match header.entry_type() {
@ -19,7 +20,7 @@ fn inode_from_entry<R: Read>(entry: &mut tar::Entry<R>) -> Result<Inode, Reposit
tar::EntryType::Directory => FileType::Directory,
_ => return Err(InodeError::UnsupportedFiletype(path.to_path_buf()).into())
};
let mut inode = Inode {
Inode {
file_type: file_type,
name: path.file_name().map(|s| s.to_string_lossy().to_string()).unwrap_or_else(|| "/".to_string()),
symlink_target: try!(entry.link_name()).map(|s| s.to_string_lossy().to_string()),
@ -29,7 +30,17 @@ fn inode_from_entry<R: Read>(entry: &mut tar::Entry<R>) -> Result<Inode, Reposit
group: try!(header.gid()),
timestamp: try!(header.mtime()) as i64,
..Default::default()
}
};
if let Some(exts) = try!(entry.pax_extensions()) {
for ext in exts {
let ext = try!(ext);
let key = ext.key().unwrap_or("");
if key.starts_with("SCHILY.xattr.") {
inode.xattrs.insert(key[13..].to_string(), ext.value_bytes().to_vec().into());
}
}
}
if inode.file_type == FileType::Directory {
inode.children = Some(BTreeMap::new());
}