Skip to content

Commit

Permalink
fix: clear temp root dir instead delete (#2312)
Browse files Browse the repository at this point in the history
  • Loading branch information
skylot committed Oct 22, 2024
1 parent 8a34d97 commit 3d5e225
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
2 changes: 1 addition & 1 deletion jadx-core/src/main/java/jadx/api/JadxDecompiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ public void close() {
closeInputs();
closeLoaders();
args.close();
FileUtils.deleteTempRootDir();
FileUtils.clearTempRootDir();
}

private void closeInputs() {
Expand Down
28 changes: 25 additions & 3 deletions jadx-core/src/main/java/jadx/core/utils/files/FileUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public static void deleteDirIfExists(Path dir) {
}
}

private static final SimpleFileVisitor<Path> FILE_DELETE_VISITOR = new SimpleFileVisitor<Path>() {
private static final SimpleFileVisitor<Path> FILE_DELETE_VISITOR = new SimpleFileVisitor<>() {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
Files.delete(file);
Expand All @@ -174,8 +174,30 @@ private static void deleteDir(Path dir) {
}
}

public static void deleteTempRootDir() {
deleteDirIfExists(tempRootDir);
public static void clearTempRootDir() {
clearDir(tempRootDir);
}

public static void clearDir(Path clearDir) {
try {
Files.walkFileTree(clearDir, Collections.emptySet(), Integer.MAX_VALUE, new SimpleFileVisitor<>() {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
Files.delete(file);
return FileVisitResult.CONTINUE;
}

@Override
public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
if (!dir.equals(clearDir)) {
Files.delete(dir);
}
return FileVisitResult.CONTINUE;
}
});
} catch (Exception e) {
throw new JadxRuntimeException("Failed to clear directory " + clearDir, e);
}
}

public static Path createTempDir(String prefix) {
Expand Down

0 comments on commit 3d5e225

Please sign in to comment.