pub fn build_archive_from_paths<W>(input_filenames: &[PathBuf], writer: W) -> crate::Result<W>
where
    W: Write,
{
    let mut builder = tar::Builder::new(writer);

    for filename in input_filenames {
        let previous_location = utils::cd_into_same_dir_as(filename)?;

        // Safe unwrap, input shall be treated before
        let filename = filename.file_name().unwrap();

        for entry in WalkDir::new(&filename) {
            let entry = entry?;
            let path = entry.path();

            info!("Compressing '{}'.", utils::to_utf(path));

            if path.is_dir() {
                builder.append_dir(path, path)?;
            } else {
                let mut file = fs::File::open(path)?;
                builder.append_file(path, file.file_mut()).map_err(|err| {
                    FinalError::with_title("Could not create archive")
                        .detail("Unexpected error while trying to read file")
                        .detail(format!("Error: {}.", err))
                })?;
            }
        }
        env::set_current_dir(previous_location)?;
    }

    Ok(builder.into_inner()?)
}
/// Compresses the archives given by `input_filenames` into the file given previously to `writer`.
Compresses the archives given by `input_filenames` into the file given previously to `writer`.
Compresses the archives given by ` input_filenames ` into the file given previously to ` writer ` .
pub fn build_archive_from_paths<W>(input_filenames: &[PathBuf], writer: W) -> crate::Result<W>
where
    W: Write,
{
    let mut builder = tar::Builder::new(writer);
    for filename in input_filenames {
        let previous_location = utils::cd_into_same_dir_as(filename)?;
        // Safe unwrap, input shall be treated before
        let filename = filename.file_name().unwrap();
        for entry in WalkDir::new(&filename) {
            let entry = entry?;
            let path = entry.path();
            info!("Compressing '{}'.", utils::to_utf(path));
            if path.is_dir() {
                builder.append_dir(path, path)?;
            } else {
                let mut file = fs::File::open(path)?;
                builder.append_file(path, file.file_mut()).map_err(|err| {
                    FinalError::with_title("Could not create archive")
                        .detail("Unexpected error while trying to read file")
                        .detail(format!("Error: {}.", err))
                })?;
            }
        }
        env::set_current_dir(previous_location)?;
    }
    Ok(builder.into_inner()?)
}
pub fn build_archive_from_paths < W > ( input_filenames : & [ PathBuf ] , writer : W ) -> crate :: Result < W > where W : Write , { let mut builder = tar :: Builder :: new ( writer ) ; for filename in input_filenames { let previous_location = utils :: cd_into_same_dir_as ( filename ) ? ; // Safe unwrap, input shall be treated before let filename = filename . file_name ( ) . unwrap ( ) ; for entry in WalkDir :: new ( & filename ) { let entry = entry ? ; let path = entry . path ( ) ; info ! ( " " utils to_utf ( path ) ) ; if path . is_dir ( ) { builder . append_dir ( path , path ) ? ; } else { let mut file = fs :: File :: open ( path ) ? ; builder . append_file ( path , file . file_mut ( ) ) . map_err ( | err | { FinalError :: with_title ( " " ) . detail ( " " ) . detail ( format ! ( " " err ) ) } ) ? ; } } env :: set_current_dir ( previous_location ) ? ; } Ok ( builder . into_inner ( ) ? ) }
Compresses the archives given by `input_filenames` into the file given previously to `writer`.
Compresses the archives given by ` input_filenames ` into the file given previously to ` writer ` .
input_filenames
&[PathBuf]
writer
W
input_filenames
&[PathBuf]
writer
W