Cherry-pick to fix EntryMaker issue

This commit is contained in:
Octavia Togami
2019-12-16 03:00:12 -08:00
committed by IronApollo
parent 735a37ffd0
commit ff47e6f717
29 changed files with 435 additions and 300 deletions

View File

@ -27,6 +27,7 @@ import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.util.report.Unreported;
import com.sk89q.worldedit.world.registry.LegacyMapper;
import com.sk89q.worldedit.world.snapshot.SnapshotRepository;
import com.sk89q.worldedit.world.snapshot.experimental.fs.FileSystemSnapshotDatabase;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -37,6 +38,10 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.UncheckedIOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Properties;

View File

@ -118,9 +118,8 @@ public class YAMLConfiguration extends LocalConfiguration {
serverSideCUI = config.getBoolean("server-side-cui", true);
String snapshotsDir = config.getString("snapshots.directory", "");
if (!snapshotsDir.isEmpty()) {
snapshotRepo = new SnapshotRepository(snapshotsDir);
}
boolean experimentalSnapshots = config.getBoolean("snapshots.experimental", false);
initializeSnapshotConfiguration(snapshotsDir, experimentalSnapshots);
String type = config.getString("shell-save-type", "").trim();
shellSaveType = type.isEmpty() ? null : type;

View File

@ -20,7 +20,6 @@
package com.sk89q.worldedit.util.function;
import java.io.IOException;
import java.io.UncheckedIOException;
/**
* I/O runnable type.
@ -28,16 +27,6 @@ import java.io.UncheckedIOException;
@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

@ -20,7 +20,6 @@
package com.sk89q.worldedit.util.io.file;
import java.io.IOException;
import java.nio.file.FileSystem;
import java.nio.file.Path;
import java.util.Optional;
@ -35,6 +34,6 @@ public interface ArchiveNioSupport {
* @param archive the archive to open
* @return the path for the root of the archive, if available
*/
Optional<ArchiveDir> tryOpenAsDir(Path archive) throws IOException;
Optional<Path> tryOpenAsDir(Path archive) throws IOException;
}

View File

@ -0,0 +1,40 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.util.io.file;
import java.io.IOException;
import java.nio.file.FileSystem;
import java.nio.file.Path;
import java.util.Optional;
/**
* Something that can provide access to an archive file as a file system.
*/
public interface ArchiveNioSupport {
/**
* Try to open the given archive as a file system.
*
* @param archive the archive to open
* @return the path for the root of the archive, if available
*/
Optional<Path> tryOpenAsDir(Path archive) throws IOException;
}

View File

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

View File

@ -22,7 +22,6 @@ 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;
@ -46,28 +45,15 @@ public final class TrueVfsArchiveNioSupport implements ArchiveNioSupport {
}
@Override
public Optional<ArchiveDir> tryOpenAsDir(Path archive) throws IOException {
public Optional<Path> 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();
}
TFileSystem fileSystem = new TPath(archive).getFileSystem();
TPath root = fileSystem.getPath("/");
Path realRoot = ArchiveNioSupports.skipRootSameName(
TPath root = new TPath(archive).getFileSystem().getPath("/");
return Optional.of(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,28 +37,17 @@ public final class ZipArchiveNioSupport implements ArchiveNioSupport {
}
@Override
public Optional<ArchiveDir> tryOpenAsDir(Path archive) throws IOException {
public Optional<Path> tryOpenAsDir(Path archive) throws IOException {
if (!archive.getFileName().toString().endsWith(".zip")) {
return Optional.empty();
}
FileSystem zipFs = FileSystems.newFileSystem(
archive, getClass().getClassLoader()
);
Path root = ArchiveNioSupports.skipRootSameName(
return Optional.of(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();
}
});
));
}
}