Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,9 +353,19 @@ impl<'a> Extract<'a> {
let mut archive = zip::ZipArchive::new(source)?;
for i in 0..archive.len() {
let mut file = archive.by_index(i)?;
let path = into_dir.join(file.name());
let mut output = fs::File::create(path)?;
io::copy(&mut file, &mut output)?;
let outpath = into_dir.join(file.sanitized_name());

if (&*file.name()).ends_with('/') {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you use outpath.is_dir() instead to be windows compatible

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was copy pasted from zip-rs example, but yes I can.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doing that causes the program to think everything is a file. I think this is mostly due to zip-rs handling folders as files and only making the difference using the ending /.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hm, that's unfortunate... Do you know if that's also the case on windows? Could you maybe setup a test zip file with nested dirs and add windows-cfg'd/linux-cfg'd tests that check this?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the reason for the is_dir to not work is because of the sanitized_name call, which might be removing the trailing slash.

I'm a bit(very) short on time currently, so I don't want to spend a lot of time on this bug fix writing unit tests. Sorry!

fs::create_dir_all(&outpath)?;
} else {
if let Some(p) = outpath.parent() {
if !p.exists() {
fs::create_dir_all(&p)?;
}
}
let mut outfile = fs::File::create(&outpath)?;
io::copy(&mut file, &mut outfile)?;
}
}
}
};
Expand Down