zip exclude dir

This commit is contained in:
phiresky 2019-06-06 16:48:31 +02:00
parent cd1a26ffff
commit 92eb76e534

View File

@ -1,5 +1,6 @@
use super::*; use super::*;
use crate::preproc::rga_preproc; use crate::preproc::rga_preproc;
use ::zip::read::ZipFile;
use failure::*; use failure::*;
use lazy_static::lazy_static; use lazy_static::lazy_static;
use std::fs::File; use std::fs::File;
@ -32,6 +33,15 @@ impl GetMetadata for ZipAdapter {
} }
} }
// https://github.com/mvdnes/zip-rs/commit/b9af51e654793931af39f221f143b9dea524f349
fn is_dir(f: &ZipFile) -> bool {
f.name()
.chars()
.rev()
.next()
.map_or(false, |c| c == '/' || c == '\\')
}
impl FileAdapter for ZipAdapter { impl FileAdapter for ZipAdapter {
fn adapt(&self, ai: AdaptInfo) -> Fallible<()> { fn adapt(&self, ai: AdaptInfo) -> Fallible<()> {
use std::io::prelude::*; use std::io::prelude::*;
@ -46,6 +56,9 @@ impl FileAdapter for ZipAdapter {
match ::zip::read::read_zipfile_from_stream(&mut inp) { match ::zip::read::read_zipfile_from_stream(&mut inp) {
Ok(None) => break, Ok(None) => break,
Ok(Some(mut file)) => { Ok(Some(mut file)) => {
if is_dir(&file) {
continue;
}
eprintln!( eprintln!(
"{}|{}: {} bytes ({} bytes packed)", "{}|{}: {} bytes ({} bytes packed)",
filepath_hint.to_string_lossy(), filepath_hint.to_string_lossy(),