Accidentally fixed the EntryMaker issue before I pulled 374ad99. Should reflect upstream now.
This commit is contained in:
Octavia Togami
2020-04-05 12:17:26 -04:00
committed by IronApollo
parent 8b97a11fa4
commit 415e91b519
10 changed files with 209 additions and 168 deletions

View File

@ -20,6 +20,7 @@
package com.sk89q.worldedit.util.function;
import java.io.IOException;
import java.io.UncheckedIOException;
/**
* I/O runnable type.
@ -27,6 +28,16 @@ import java.io.IOException;
@FunctionalInterface
public interface IORunnable {
static Runnable unchecked(IORunnable runnable) {
return () -> {
try {
runnable.run();
} catch (IOException e) {
throw new UncheckedIOException(e);
}
};
}
void run() throws IOException;
}

View File

@ -34,6 +34,6 @@ public interface ArchiveNioSupport {
* @param archive the archive to open
* @return the path for the root of the archive, if available
*/
Optional<Path> tryOpenAsDir(Path archive) throws IOException;
Optional<ArchiveDir> tryOpenAsDir(Path archive) throws IOException;
}

View File

@ -45,9 +45,9 @@ public class ArchiveNioSupports {
.build();
}
public static Optional<Path> tryOpenAsDir(Path archive) throws IOException {
public static Optional<ArchiveDir> tryOpenAsDir(Path archive) throws IOException {
for (ArchiveNioSupport support : SUPPORTS) {
Optional<Path> fs = support.tryOpenAsDir(archive);
Optional<ArchiveDir> fs = support.tryOpenAsDir(archive);
if (fs.isPresent()) {
return fs;
}

View File

@ -22,6 +22,7 @@ package com.sk89q.worldedit.util.io.file;
import com.google.common.base.Splitter;
import com.google.common.collect.ImmutableSet;
import net.java.truevfs.access.TArchiveDetector;
import net.java.truevfs.access.TFileSystem;
import net.java.truevfs.access.TPath;
import java.io.IOException;
@ -45,15 +46,28 @@ public final class TrueVfsArchiveNioSupport implements ArchiveNioSupport {
}
@Override
public Optional<Path> tryOpenAsDir(Path archive) throws IOException {
public Optional<ArchiveDir> tryOpenAsDir(Path archive) throws IOException {
String fileName = archive.getFileName().toString();
int dot = fileName.indexOf('.');
if (dot < 0 || dot >= fileName.length() || !ALLOWED_EXTENSIONS.contains(fileName.substring(dot + 1))) {
if (dot < 0 || dot >= fileName.length() || !ALLOWED_EXTENSIONS
.contains(fileName.substring(dot + 1))) {
return Optional.empty();
}
TPath root = new TPath(archive).getFileSystem().getPath("/");
return Optional.of(ArchiveNioSupports.skipRootSameName(
TFileSystem fileSystem = new TPath(archive).getFileSystem();
TPath root = fileSystem.getPath("/");
Path realRoot = ArchiveNioSupports.skipRootSameName(
root, fileName.substring(0, dot)
));
);
return Optional.of(new ArchiveDir() {
@Override
public Path getPath() {
return realRoot;
}
@Override
public void close() throws IOException {
fileSystem.close();
}
});
}
}

View File

@ -37,17 +37,28 @@ public final class ZipArchiveNioSupport implements ArchiveNioSupport {
}
@Override
public Optional<Path> tryOpenAsDir(Path archive) throws IOException {
public Optional<ArchiveDir> tryOpenAsDir(Path archive) throws IOException {
if (!archive.getFileName().toString().endsWith(".zip")) {
return Optional.empty();
}
FileSystem zipFs = FileSystems.newFileSystem(
archive, getClass().getClassLoader()
);
return Optional.of(ArchiveNioSupports.skipRootSameName(
Path root = ArchiveNioSupports.skipRootSameName(
zipFs.getPath("/"), archive.getFileName().toString()
.replaceFirst("\\.zip$", "")
));
);
return Optional.of(new ArchiveDir() {
@Override
public Path getPath() {
return root;
}
@Override
public void close() throws IOException {
zipFs.close();
}
});
}
}