Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. use std::fs::File;
  2. use std::io::{Error, Read};
  3. use std::path::Path;
  4.  
  5. pub fn untar(tar_file: &Path, destination_dir: &Path, is_tar_gz: bool) -> Result<(), Error> {
  6. let file = File::open(tar_file)?;
  7. let archive = if is_tar_gz {
  8. let decoder = flate2::read::GzDecoder::new(file);
  9. tar::Archive::new(decoder)
  10. } else {
  11. tar::Archive::new(file)
  12. };
  13. unpack(archive, &destination_dir)
  14. }
  15.  
  16. fn unpack<R: Read>(mut archive: tar::Archive<R>, destination_dir: &Path) -> Result<(), Error> {
  17. archive.set_preserve_permissions(true);
  18. archive.set_preserve_mtime(true);
  19. Ok(archive.unpack(&destination_dir)?)
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement