Skip to content

Commit c10cd34

Browse files
authored
Merge pull request #168
* Yeet * Wait this is wrong * Merge branch 'develop' into namespace-change
1 parent 746d5de commit c10cd34

1 file changed

Lines changed: 21 additions & 7 deletions

File tree

  • station-api-base/src/main/java/net/modificationstation/stationapi/api/util

station-api-base/src/main/java/net/modificationstation/stationapi/api/util/Namespace.java

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import net.fabricmc.loader.api.ModContainer;
1414
import net.fabricmc.loader.api.Version;
1515
import net.fabricmc.loader.api.metadata.ModMetadata;
16-
import net.fabricmc.loader.impl.util.FileSystemUtil;
1716
import net.modificationstation.stationapi.api.util.exception.MissingModException;
1817
import org.apache.logging.log4j.Level;
1918
import org.apache.logging.log4j.LogManager;
@@ -26,16 +25,18 @@
2625
import java.io.IOException;
2726
import java.net.URI;
2827
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;
3231
import java.util.function.Function;
3332
import java.util.function.Supplier;
3433
import java.util.stream.Stream;
34+
import java.util.zip.ZipError;
3535

3636
@Slf4j
3737
public final class Namespace implements Comparable<@NotNull Namespace> {
3838
private static final boolean CHECK_MISSING_MODS = false;
39+
private static final Map<String, String> CREATE_FILESYSTEM_ARGS = Collections.singletonMap("create", "true");
3940

4041
@NotNull
4142
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> {
7778
// i'm so sorry
7879
if (Files.isRegularFile(callerPath)) { // regular case
7980
final URI callerRoot;
81+
val uri = callerPath.toUri();
8082
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+
}
8394
callerRoot = fs.getPath("/").toUri();
84-
} catch (IOException e) {
95+
if (created) {
96+
fs.close();
97+
}
98+
} catch (IOException | URISyntaxException e) {
8599
throw new RuntimeException(e);
86100
}
87101
candidates = mods

0 commit comments

Comments
 (0)