|
13 | 13 | import net.fabricmc.loader.api.ModContainer; |
14 | 14 | import net.fabricmc.loader.api.Version; |
15 | 15 | import net.fabricmc.loader.api.metadata.ModMetadata; |
16 | | -import net.fabricmc.loader.impl.util.FileSystemUtil; |
17 | 16 | import net.modificationstation.stationapi.api.util.exception.MissingModException; |
18 | 17 | import org.apache.logging.log4j.Level; |
19 | 18 | import org.apache.logging.log4j.LogManager; |
|
26 | 25 | import java.io.IOException; |
27 | 26 | import java.net.URI; |
28 | 27 | import java.net.URISyntaxException; |
29 | | -import java.nio.file.Files; |
30 | | -import java.nio.file.Path; |
31 | | -import java.nio.file.Paths; |
| 28 | +import java.nio.file.*; |
| 29 | +import java.util.Collections; |
| 30 | +import java.util.Map; |
32 | 31 | import java.util.function.Function; |
33 | 32 | import java.util.function.Supplier; |
34 | 33 | import java.util.stream.Stream; |
| 34 | +import java.util.zip.ZipError; |
35 | 35 |
|
36 | 36 | @Slf4j |
37 | 37 | public final class Namespace implements Comparable<@NotNull Namespace> { |
38 | 38 | private static final boolean CHECK_MISSING_MODS = false; |
| 39 | + private static final Map<String, String> CREATE_FILESYSTEM_ARGS = Collections.singletonMap("create", "true"); |
39 | 40 |
|
40 | 41 | @NotNull |
41 | 42 | private static final Cache<@NotNull String, @NotNull Namespace> CACHE = Caffeine.newBuilder().softValues().build(); |
@@ -77,11 +78,24 @@ public final class Namespace implements Comparable<@NotNull Namespace> { |
77 | 78 | // i'm so sorry |
78 | 79 | if (Files.isRegularFile(callerPath)) { // regular case |
79 | 80 | final URI callerRoot; |
| 81 | + val uri = callerPath.toUri(); |
80 | 82 | try { |
81 | | - // do NOT close - the same FileSystem may be used by Fabric Loader! |
82 | | - val fs = FileSystemUtil.getJarFileSystem(callerPath, false).get(); |
| 83 | + FileSystem fs; |
| 84 | + boolean created = false; |
| 85 | + val jarUri = new URI("jar:" + uri.getScheme(), uri.getHost(), uri.getPath(), uri.getFragment()); |
| 86 | + try { |
| 87 | + fs = FileSystems.newFileSystem(jarUri, CREATE_FILESYSTEM_ARGS); |
| 88 | + created = true; |
| 89 | + } catch (FileSystemAlreadyExistsException ignore2) { |
| 90 | + fs = FileSystems.getFileSystem(jarUri); |
| 91 | + } catch (IOException | ZipError e) { |
| 92 | + throw new IOException("Error accessing " + uri + ": " + e, e); |
| 93 | + } |
83 | 94 | callerRoot = fs.getPath("/").toUri(); |
84 | | - } catch (IOException e) { |
| 95 | + if (created) { |
| 96 | + fs.close(); |
| 97 | + } |
| 98 | + } catch (IOException | URISyntaxException e) { |
85 | 99 | throw new RuntimeException(e); |
86 | 100 | } |
87 | 101 | candidates = mods |
|
0 commit comments