Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes system-files not being ignored by ZIP-native extractor when executing an import-job #2059

Merged
merged 11 commits into from
Dec 11, 2024
Merged
10 changes: 9 additions & 1 deletion src/main/java/sirius/biz/jobs/batch/file/ArchiveImportJob.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.util.Arrays;
import java.util.Collections;
import java.util.Enumeration;
import java.util.List;
import java.util.Optional;
import java.util.function.Consumer;
import java.util.stream.Stream;
Expand All @@ -43,6 +44,11 @@ public abstract class ArchiveImportJob extends FileImportJob {

private static final String ZIP_FILE_EXTENSION = "zip";

/**
* Contains a list of file names which should be ignored when extracting files from the archive.
*/
private static final List <String> FILE_FILTER = List.of("__MACOSX");

/**
* Contains a customized parameter which should be used in {@link FileImportJobFactory#createFileParameter()}
* in its factory.
Expand Down Expand Up @@ -104,7 +110,9 @@ protected Optional<ExtractedFile> fetchEntry(String fileName) throws IOException
Enumeration<? extends ZipEntry> zipEntries = zipFile.entries();
while (zipEntries.hasMoreElements() && taskContext.isActive()) {
ZipEntry zipEntry = zipEntries.nextElement();

if (FILE_FILTER.stream().anyMatch(zipEntry.getName()::contains)) {
scireum-mbo marked this conversation as resolved.
Show resolved Hide resolved
continue;
}
if (Strings.areEqual(fileName, zipEntry.getName())) {
return Optional.of(new ExtractedZipFile(zipEntry,
() -> zipFile.getInputStream(zipEntry),
Expand Down
Loading