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
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<url>https://www.sirius-lib.net</url>

<properties>
<sirius.kernel>dev-44.0.0</sirius.kernel>
<sirius.kernel>dev-44.1.0</sirius.kernel>
<sirius.web>dev-86.1.0</sirius.web>
<sirius.db>dev-59.0.0</sirius.db>
</properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import sirius.biz.util.ExtractedZipFile;
import sirius.kernel.async.TaskContext;
import sirius.kernel.commons.Amount;
import sirius.kernel.commons.Files;
import sirius.kernel.commons.Producer;
import sirius.kernel.commons.Strings;
import sirius.kernel.health.Exceptions;
Expand All @@ -30,6 +31,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 Down Expand Up @@ -104,7 +106,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 (Files.isConsideredHidden(zipEntry.getName()) || Files.isConsideredMetadata(zipEntry.getName())) {
idlira 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
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import sirius.kernel.async.TaskContext;
import sirius.kernel.commons.Callback;
import sirius.kernel.commons.Context;
import sirius.kernel.commons.Files;
import sirius.kernel.commons.Tuple;
import sirius.kernel.commons.UnitOfWork;
import sirius.web.data.LineBasedProcessor;
Expand Down Expand Up @@ -177,7 +178,9 @@ protected void importEntries() throws Exception {
handleMissingFile(importFile.filename, importFile.required);
}

handledFiles.add(importFile.filename);
if(!(Files.isConsideredHidden(importFile.filename) || Files.isConsideredMetadata(importFile.filename))) {
scireum-mbo marked this conversation as resolved.
Show resolved Hide resolved
handledFiles.add(importFile.filename);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import sirius.biz.tycho.QuickAction;
import sirius.biz.tycho.UserAssistant;
import sirius.biz.web.BizController;
import sirius.kernel.commons.Files;
import sirius.kernel.commons.Limit;
import sirius.kernel.commons.Streams;
import sirius.kernel.commons.Strings;
Expand Down Expand Up @@ -380,7 +381,7 @@ private void outputChildren(WebContext webContext, JSONStructuredOutput output,
Arrays.stream(extensionString.asString().split(","))
.map(Strings::trim)
.filter(Strings::isFilled)
.map(string -> string.startsWith(".") ? string.substring(1) : string)
.map(string -> Files.isConsideredHidden(string) ? string.substring(1) : string)
.forEach(search::withFileExtension);
});

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/sirius/biz/storage/s3/ObjectStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ protected ObjectStore(ObjectStores stores, String name, AmazonS3 client, String
.withS3Client(client)
.build();

if (Strings.isFilled(bucketSuffix) && bucketSuffix.contains(".") && !bucketSuffix.startsWith(".")) {
if (Strings.isFilled(bucketSuffix) && bucketSuffix.contains(".") && !Files.isConsideredHidden(bucketSuffix)) {
ObjectStores.LOG.WARN(
"The bucketSuffix '%s' contains a '.' but does not start with one. This might lead to errors!",
bucketSuffix);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/sirius/biz/util/ArchiveExtractor.java
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ private Predicate<String> enhanceFileFilter(@Nullable Predicate<String> filter)

private boolean ignoreHiddenFiles(String path) {
String filename = Files.getFilenameAndExtension(path);
return Strings.isFilled(filename) && !filename.startsWith(".") && !filename.startsWith("__MACOSX");
return Strings.isFilled(filename) && !Files.isConsideredHidden(filename) && !Files.isConsideredMetadata(path);
}

private void extractZip(File archiveFile,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,15 @@ public ISequentialOutStream getStream(int index, ExtractAskMode extractAskMode)
skipExtraction |= (attributes & PropID.AttributesBitMask.FILE_ATTRIBUTE_HIDDEN) != 0;
}
if (filePath != null) {
skipExtraction |= filePath.startsWith("__MACOSX");
skipExtraction |= Files.isConsideredMetadata(filePath);
if (filter != null) {
skipExtraction |= !filter.apply(filePath);
}
}
if (fileName != null) {
// need to filter hidden files (starting with dot), because some tar implementations create
// hidden index files (ending with xml, too)
skipExtraction |= fileName.startsWith(".");
skipExtraction |= Files.isConsideredHidden(fileName);
}

if (skipExtraction) {
Expand Down
Loading