mirror of https://github.com/dswd/zvault
Exporting user/group names in tar files (re #2)
This commit is contained in:
parent
efbd374678
commit
6444ed7076
|
@ -8,6 +8,7 @@ This project follows [semantic versioning](http://semver.org).
|
|||
- [added] Locking local repository to avoid index corruption
|
||||
- [added] Storing user/group names in backup
|
||||
- [modified] No longer trying to upload by rename
|
||||
- [modified] No longer failing restore if setting file attributes fails
|
||||
- [fixed] Creating empty bundle cache on init to avoid warnings
|
||||
- [fixed] Calling sodiumoxide::init for faster algorithms and thread safety (not needed)
|
||||
- [fixed] Fixed a deadlock in the bundle upload code
|
||||
|
|
|
@ -380,7 +380,7 @@ pub fn run() -> Result<(), ErrorCode> {
|
|||
checked!(repo.get_inode(&backup.root), "load root inode", ErrorCode::LoadInode)
|
||||
};
|
||||
if tar {
|
||||
checked!(repo.export_tarfile(inode, &dst_path), "restore backup", ErrorCode::RestoreRun);
|
||||
checked!(repo.export_tarfile(&backup, inode, &dst_path), "restore backup", ErrorCode::RestoreRun);
|
||||
} else {
|
||||
checked!(repo.restore_inode_tree(&backup, inode, &dst_path), "restore backup", ErrorCode::RestoreRun);
|
||||
}
|
||||
|
|
|
@ -190,7 +190,7 @@ impl Repository {
|
|||
}
|
||||
}
|
||||
|
||||
fn export_tarfile_recurse(&mut self, path: &Path, inode: Inode, tarfile: &mut tar::Builder<File>) -> Result<(), RepositoryError> {
|
||||
fn export_tarfile_recurse(&mut self, backup: &Backup, path: &Path, inode: Inode, tarfile: &mut tar::Builder<File>) -> Result<(), RepositoryError> {
|
||||
let mut header = tar::Header::new_gnu();
|
||||
header.set_size(inode.size);
|
||||
let path = path.join(inode.name);
|
||||
|
@ -200,7 +200,13 @@ impl Repository {
|
|||
}
|
||||
header.set_mode(inode.mode);
|
||||
header.set_uid(inode.user);
|
||||
if let Some(name) = backup.user_names.get(&inode.user) {
|
||||
header.set_username(name).ok();
|
||||
}
|
||||
header.set_gid(inode.group);
|
||||
if let Some(name) = backup.group_names.get(&inode.group) {
|
||||
header.set_groupname(name).ok();
|
||||
}
|
||||
header.set_mtime(inode.timestamp as u64);
|
||||
header.set_entry_type(match inode.file_type {
|
||||
FileType::File => tar::EntryType::Regular,
|
||||
|
@ -220,15 +226,15 @@ impl Repository {
|
|||
if let Some(children) = inode.children {
|
||||
for chunks in children.values() {
|
||||
let inode = try!(self.get_inode(chunks));
|
||||
try!(self.export_tarfile_recurse(&path, inode, tarfile));
|
||||
try!(self.export_tarfile_recurse(backup, &path, inode, tarfile));
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn export_tarfile<P: AsRef<Path>>(&mut self, inode: Inode, tarfile: P) -> Result<(), RepositoryError> {
|
||||
pub fn export_tarfile<P: AsRef<Path>>(&mut self, backup: &Backup, inode: Inode, tarfile: P) -> Result<(), RepositoryError> {
|
||||
let mut tarfile = tar::Builder::new(try!(File::create(tarfile)));
|
||||
try!(self.export_tarfile_recurse(Path::new(""), inode, &mut tarfile));
|
||||
try!(self.export_tarfile_recurse(backup, Path::new(""), inode, &mut tarfile));
|
||||
try!(tarfile.finish());
|
||||
Ok(())
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue