Importing extended attributes from tar files (re #1)

This commit is contained in:
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,25 +11,36 @@ use tar;
fn inode_from_entry<R: Read>(entry: &mut tar::Entry<R>) -> Result<Inode, RepositoryError> { fn inode_from_entry<R: Read>(entry: &mut tar::Entry<R>) -> Result<Inode, RepositoryError> {
let path = try!(entry.path()); let mut inode = {
let header = entry.header(); let path = try!(entry.path());
let file_type = match header.entry_type() { let header = entry.header();
tar::EntryType::Regular | tar::EntryType::Link | tar::EntryType::Continuous => FileType::File, let file_type = match header.entry_type() {
tar::EntryType::Symlink => FileType::Symlink, tar::EntryType::Regular | tar::EntryType::Link | tar::EntryType::Continuous => FileType::File,
tar::EntryType::Directory => FileType::Directory, tar::EntryType::Symlink => FileType::Symlink,
_ => return Err(InodeError::UnsupportedFiletype(path.to_path_buf()).into()) tar::EntryType::Directory => FileType::Directory,
}; _ => return Err(InodeError::UnsupportedFiletype(path.to_path_buf()).into())
let mut inode = Inode { };
file_type: file_type, Inode {
name: path.file_name().map(|s| s.to_string_lossy().to_string()).unwrap_or_else(|| "/".to_string()), file_type: file_type,
symlink_target: try!(entry.link_name()).map(|s| s.to_string_lossy().to_string()), name: path.file_name().map(|s| s.to_string_lossy().to_string()).unwrap_or_else(|| "/".to_string()),
size: try!(header.size()), symlink_target: try!(entry.link_name()).map(|s| s.to_string_lossy().to_string()),
mode: try!(header.mode()), size: try!(header.size()),
user: try!(header.uid()), mode: try!(header.mode()),
group: try!(header.gid()), user: try!(header.uid()),
timestamp: try!(header.mtime()) as i64, group: try!(header.gid()),
..Default::default() 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 { if inode.file_type == FileType::Directory {
inode.children = Some(BTreeMap::new()); inode.children = Some(BTreeMap::new());
} }