Introduce some try-with-resource blocks in an attempt to fix windows
This commit is contained in:
parent
a0207bb153
commit
5af47bf460
|
@ -6,8 +6,7 @@ import java.nio.file.attribute.BasicFileAttributes;
|
|||
|
||||
public class RemoveDirVisitor extends SimpleFileVisitor<Path> {
|
||||
@Override
|
||||
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException
|
||||
{
|
||||
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
|
||||
Files.delete(file);
|
||||
return FileVisitResult.CONTINUE;
|
||||
}
|
||||
|
|
|
@ -28,8 +28,9 @@ public class PruneVanillaProcessor extends PackProcessor {
|
|||
try {
|
||||
InputStream vn = cl.getResourceAsStream(p.getPath("/").relativize(s).toString());
|
||||
if (vn != null) {
|
||||
InputStream pk = Files.newInputStream(s, StandardOpenOption.READ);
|
||||
return IOUtils.contentEquals(vn, pk);
|
||||
try (InputStream pk = Files.newInputStream(s, StandardOpenOption.READ)) {
|
||||
return IOUtils.contentEquals(vn, pk);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Throwable e) {
|
||||
|
|
|
@ -4,8 +4,10 @@ import io.gitlab.jfronny.resclone.data.RescloneException;
|
|||
import io.gitlab.jfronny.resclone.io.PathPruneVisitor;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.DirectoryStream;
|
||||
import java.nio.file.FileSystem;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
public class RemoveEmptyProcessor extends PackProcessor {
|
||||
@Override
|
||||
|
@ -14,8 +16,8 @@ public class RemoveEmptyProcessor extends PackProcessor {
|
|||
try {
|
||||
Files.walkFileTree(p.getPath("/assets"), new PathPruneVisitor(s -> {
|
||||
if (Files.isDirectory(s)) {
|
||||
try {
|
||||
return !Files.newDirectoryStream(s).iterator().hasNext();
|
||||
try (DirectoryStream<Path> paths = Files.newDirectoryStream(s)) {
|
||||
return !paths.iterator().hasNext();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
|
|
@ -4,10 +4,7 @@ import io.gitlab.jfronny.resclone.io.MoveDirVisitor;
|
|||
import io.gitlab.jfronny.resclone.data.RescloneException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.FileSystem;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
import java.nio.file.*;
|
||||
|
||||
public class RootPathProcessor extends PackProcessor {
|
||||
@Override
|
||||
|
@ -15,9 +12,11 @@ public class RootPathProcessor extends PackProcessor {
|
|||
if (!Files.exists(p.getPath("/pack.mcmeta"))) {
|
||||
try {
|
||||
Path root = p.getPath("/");
|
||||
for (Path path : Files.newDirectoryStream(root)) {
|
||||
if (Files.isDirectory(path) && Files.exists(path.resolve("pack.mcmeta"))) {
|
||||
Files.walkFileTree(path, new MoveDirVisitor(path, root, StandardCopyOption.REPLACE_EXISTING));
|
||||
try (DirectoryStream<Path> paths = Files.newDirectoryStream(root)) {
|
||||
for (Path path : paths) {
|
||||
if (Files.isDirectory(path) && Files.exists(path.resolve("pack.mcmeta"))) {
|
||||
Files.walkFileTree(path, new MoveDirVisitor(path, root, StandardCopyOption.REPLACE_EXISTING));
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
|
|
Loading…
Reference in New Issue