Slightly safer zip file system access
This commit is contained in:
parent
572943ead0
commit
450eb83c13
|
@ -42,7 +42,7 @@ ext {
|
|||
imguiVersion = '1.86.4'
|
||||
slf4jVersion = '1.7.36'
|
||||
logbackVersion = '1.2.11'
|
||||
jfCommonsVersion = '2022.6.5+13-35-53'
|
||||
jfCommonsVersion = '2022.6.27+12-28-9'
|
||||
jgitVersion = '6.1.0.202203080745-r'
|
||||
flavorProp = project.hasProperty('flavor') ? project.getProperty('flavor') : 'custom'
|
||||
flavor = flavorProp
|
||||
|
|
|
@ -1,25 +1,26 @@
|
|||
package io.gitlab.jfronny.inceptum.util;
|
||||
|
||||
import io.gitlab.jfronny.commons.*;
|
||||
import io.gitlab.jfronny.commons.log.*;
|
||||
import io.gitlab.jfronny.commons.serialize.gson.api.*;
|
||||
import io.gitlab.jfronny.commons.throwable.*;
|
||||
import io.gitlab.jfronny.inceptum.*;
|
||||
import io.gitlab.jfronny.inceptum.util.cache.*;
|
||||
import io.gitlab.jfronny.commons.io.MultiAccessFileSystem;
|
||||
import io.gitlab.jfronny.commons.log.Logger;
|
||||
import io.gitlab.jfronny.commons.serialize.gson.api.GsonHolder;
|
||||
import io.gitlab.jfronny.commons.throwable.ThrowingConsumer;
|
||||
import io.gitlab.jfronny.commons.throwable.ThrowingSupplier;
|
||||
import io.gitlab.jfronny.inceptum.WrapperStrap;
|
||||
import io.gitlab.jfronny.inceptum.util.cache.GsonFileCache;
|
||||
|
||||
import java.awt.*;
|
||||
import java.io.*;
|
||||
import java.lang.reflect.*;
|
||||
import java.lang.reflect.Type;
|
||||
import java.net.*;
|
||||
import java.nio.charset.*;
|
||||
import java.nio.file.FileSystem;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.*;
|
||||
import java.nio.file.attribute.*;
|
||||
import java.util.List;
|
||||
import java.nio.file.attribute.BasicFileAttributes;
|
||||
import java.util.*;
|
||||
import java.util.function.*;
|
||||
import java.util.regex.*;
|
||||
import java.util.stream.*;
|
||||
import java.util.List;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class Utils {
|
||||
public static final Pattern VALID_FILENAME = Pattern.compile("[a-zA-Z0-9_\\-.][a-zA-Z0-9 _\\-.]*[a-zA-Z0-9_\\-.]");
|
||||
|
@ -257,14 +258,14 @@ public class Utils {
|
|||
}
|
||||
}
|
||||
|
||||
private static final Map<Path, FileSystem> zipFsCache = new HashMap<>();
|
||||
private static final Map<Path, MultiAccessFileSystem> zipFsCache = new HashMap<>();
|
||||
public static FileSystem openZipFile(Path zip, boolean create) throws IOException, URISyntaxException {
|
||||
synchronized (zipFsCache) {
|
||||
if (!zipFsCache.containsKey(zip) || !zipFsCache.get(zip).isOpen()) {
|
||||
if (!zipFsCache.containsKey(zip) || !zipFsCache.get(zip).isClosed()) {
|
||||
URI fileUri = zip.toUri();
|
||||
zipFsCache.put(zip, FileSystems.newFileSystem(new URI("jar:" + fileUri.getScheme(), fileUri.getPath(), null), create ? Map.of("create", "true") : Map.of(), WrapperStrap.SYSTEM_LOADER));
|
||||
zipFsCache.put(zip, MultiAccessFileSystem.create(new URI("jar:" + fileUri.getScheme(), fileUri.getPath(), null), create ? Map.of("create", "true") : Map.of(), WrapperStrap.SYSTEM_LOADER));
|
||||
}
|
||||
return zipFsCache.get(zip);
|
||||
return zipFsCache.get(zip).createLens();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue