From 325e57ce86aada44fa0d9f7e34a142e07aad9a43 Mon Sep 17 00:00:00 2001 From: Glitch Date: Fri, 5 Aug 2022 18:49:21 -0500 Subject: [PATCH] Only open JAR files if the provided input is a directory --- .../fabricmc/tinyremapper/TinyRemapper.java | 40 +++++++++++-------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/src/main/java/net/fabricmc/tinyremapper/TinyRemapper.java b/src/main/java/net/fabricmc/tinyremapper/TinyRemapper.java index a7f0c090..b35d53e5 100644 --- a/src/main/java/net/fabricmc/tinyremapper/TinyRemapper.java +++ b/src/main/java/net/fabricmc/tinyremapper/TinyRemapper.java @@ -475,17 +475,14 @@ private List>> read(final Path file, boole final boolean saveData, final List fsToClose) throws IOException { List>> ret = new ArrayList<>(); - Files.walkFileTree(file, new SimpleFileVisitor() { - @Override - public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { - String name = file.getFileName().toString(); - - if (name.endsWith(".jar") - || name.endsWith(".zip") - || name.endsWith(".class")) { - ret.add(CompletableFuture.supplyAsync(new Supplier>() { - @Override - public List get() { + if (Files.isDirectory(file)) { + Files.walkFileTree(file, new SimpleFileVisitor() { + @Override + public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) { + String name = file.getFileName().toString(); + + if (name.endsWith(".class")) { + ret.add(CompletableFuture.supplyAsync(() -> { try { return readFile(file, isInput, tags, srcPath, fsToClose); } catch (URISyntaxException e) { @@ -493,13 +490,24 @@ public List get() { } catch (IOException | ZipError e) { throw new RuntimeException("Error reading file "+file, e); } - } - }, threadPool)); + }, threadPool)); + } + + return FileVisitResult.CONTINUE; } + }); + } else { + ret.add(CompletableFuture.supplyAsync(() -> { + try { + return readFile(file, isInput, tags, srcPath, fsToClose); + } catch (URISyntaxException e) { + throw new RuntimeException(e); + } catch (IOException | ZipError e) { + throw new RuntimeException("Error reading file "+file, e); + } + })); + } - return FileVisitResult.CONTINUE; - } - }); return ret; }