Skip to content

Commit

Permalink
update createParentDirectory for safety
Browse files Browse the repository at this point in the history
  • Loading branch information
wagyourtail committed Jul 20, 2024
1 parent 13a837d commit ecf1e26
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,10 @@ public byte[] apply(String s) {
for (Map.Entry<String, byte[]> entry : outputs.entrySet()) {
String internal = entry.getKey();
Path p = out.resolve(internal + ".class");
Files.createDirectories(p.getParent());
Path parent = p.getParent();
if (parent != null) {
Files.createDirectories(parent);
}
Files.write(p, entry.getValue(), StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ public static void downgradeZip(int opcVersion, Path input, Set<URL> classpath,

public static void downgradeZip(final ClassDowngrader downgrader, Path zip, Set<URL> classpath, final Path output) throws IOException {
try (final FileSystem zipfs = Utils.openZipFileSystem(zip, false)) {
Files.createDirectories(output.getParent());
Path parent = output.getParent();
if (parent != null) {
Files.createDirectories(parent);
}
Files.deleteIfExists(output);
try (final FileSystem outputZipFs = Utils.openZipFileSystem(output, true)) {
PathDowngrader.downgradePaths(downgrader, Collections.singletonList(zipfs.getPath("/")), Collections.singletonList(outputZipFs.getPath("/")), classpath);
Expand Down
1 change: 0 additions & 1 deletion src/main/java/xyz/wagyourtail/jvmdg/runtime/Bootstrap.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ public static void premain(String args, Instrumentation instrumentation) throws
downgrade = true;
}
if (downgrade) {
Files.createDirectories(tmp.getParent());
for (File file : tmp.getParent().toFile().listFiles()) {
if (file.isDirectory()) continue;
if (file.getName().startsWith(name + "-downgraded-" + currentVersionDowngrader.target) && file.getName().endsWith(".jar")) {
Expand Down

0 comments on commit ecf1e26

Please sign in to comment.