Skip to content
Closed
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
import org.apache.commons.compress.compressors.xz.XZCompressorInputStream;
import org.apache.commons.compress.compressors.z.ZCompressorInputStream;
import org.apache.commons.io.input.CloseShieldInputStream;
import org.apache.tika.io.FilenameUtils;
import org.xml.sax.ContentHandler;
import org.xml.sax.SAXException;

Expand Down Expand Up @@ -254,6 +255,9 @@ private void setName(Metadata parentMetadata, Metadata metadata) {
if (StringUtils.isBlank(name)) {
return;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Maybe use FilenameUtils.getName(name)

name = FilenameUtils.getName(name);

if (name.endsWith(".tgz") || name.endsWith(".tbz") || name.endsWith(".tbz2")) {
name = name.substring(0, name.lastIndexOf(".")) + ".tar";
} else if (name.endsWith(".bz") || name.endsWith("gz") || name.endsWith(".bz2") || name.endsWith(".xz") || name.endsWith(".zlib") || name.endsWith(".pack") ||
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,41 @@ public void testTarball() throws Exception {
"/test-documents.tar"), actualEmbeddedPaths);
}

@Test
public void testNestedTarball() throws Exception {
List<Metadata> list = getRecursiveMetadata("test-nested-tarball.tar");
List<String> actualResourceNames =
list.stream()
.map(m -> m.get(TikaCoreProperties.RESOURCE_NAME_KEY))
.collect(Collectors.toList());

List<String> expectedResourceNames = Arrays.asList("test-nested-tarball.tar",
"folderWithinTgz/testTXT.txt",
"nested.tar",
"folderContainingTgz/inner/nested.tgz");
assertEquals(expectedResourceNames, actualResourceNames);

List<String> actualInternalPaths =
list.stream()
.map(m -> m.get(TikaCoreProperties.INTERNAL_PATH))
.collect(Collectors.toList());

List<String> expectedInternalPaths = Arrays.asList(null,
"folderWithinTgz/testTXT.txt",
null, // tar file within a gz doesn't have an internal path
"folderContainingTgz/inner/nested.tgz");
assertEquals(expectedInternalPaths, actualInternalPaths);

List<String> actualEmbeddedPaths =
list.stream()
.map(m -> m.get(TikaCoreProperties.EMBEDDED_RESOURCE_PATH))
.collect(Collectors.toList());
assertEquals(Arrays.asList(null,
"/nested.tgz/nested.tar/testTXT.txt",
"/nested.tgz/nested.tar",
"/nested.tgz"), actualEmbeddedPaths);
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Add test for internalPaths?

There are three things we care about with this change: resource names (should be just the file name), embedded resource path and the internal path.


@Test
public void testCharLimitNoThrowOnWriteLimit() throws Exception {
ParseContext context = new ParseContext();
Expand Down
Loading