Skip to content

Commit

Permalink
fix dangling zip-entries in a jar will cause an error
Browse files Browse the repository at this point in the history
  • Loading branch information
Eyre-S committed Jul 18, 2024
1 parent f9367d0 commit 2c67a0e
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version = 0.3.1
snapshot = true
snapshot = false

archive_name = resource-tools
6 changes: 6 additions & 0 deletions src/main/java/cc/sukazyo/restools/impl/jar/tree/NodeRoot.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public class NodeRoot implements IBranchNode {
@Nonnull
public final JarFile jar;
final Map<String, EntryNode> _children = new HashMap<>();
final Map<String, JarEntry> _dangling_entries = new HashMap<>();

public NodeRoot (@Nonnull JarFile jar) {
this.jar = jar;
Expand Down Expand Up @@ -41,6 +42,11 @@ public Map<String, EntryNode> children () {
return _children;
}

@Nonnull
public Map<String, JarEntry> getDanglingEntries () {
return _dangling_entries;
}

@Nonnull
@Override
public String getAbsolutePath () {
Expand Down
9 changes: 7 additions & 2 deletions src/main/java/cc/sukazyo/restools/impl/jar/tree/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,13 @@ public static NodeRoot parse (@Nonnull JarFile jar) {

final List<JarEntry> newUnresolvedEntries = new ArrayList<>();
unresolvedEntries.forEach(entry -> resolveEntry(root, entry, newUnresolvedEntries));
if (unresolvedEntries.size() == newUnresolvedEntries.size())
throw new IllegalStateException("Failed to resolve all entries due to thw following entries have no parents: " + unresolvedEntries);
if (unresolvedEntries.size() == newUnresolvedEntries.size()) {
// throw new IllegalStateException("Failed to resolve all entries due to thw following entries have no parents: " + unresolvedEntries);
for (JarEntry entry : newUnresolvedEntries) {
root._dangling_entries.put(entry.getName(), entry);
}
break;
}
unresolvedEntries = newUnresolvedEntries;

}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/cc/sukazyo/restools/utils/PathsHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class PathsHelper {
*/
@Nonnull
public static String getJarPath (@Nonnull String path) {
final int jarIdentifier = path.lastIndexOf("/") - 1;
final int jarIdentifier = path.lastIndexOf("!/");
if (jarIdentifier > 0 && path.startsWith("jar:"))
return path.substring("jar:".length(), jarIdentifier);
else return path;
Expand Down

0 comments on commit 2c67a0e

Please sign in to comment.