@@ -3,35 +3,24 @@ package net.msrandom.minecraftcodev.core.utils
33import org.gradle.api.file.FileSystemLocation
44import org.gradle.api.file.FileSystemLocationProperty
55import org.jetbrains.annotations.Blocking
6- import org.slf4j.LoggerFactory
7- import java.lang.Thread.sleep
8- import java.net.URI
96import java.nio.file.*
7+ import java.nio.file.spi.FileSystemProvider
108import kotlin.streams.asSequence
11- import kotlin.time.Duration.Companion.seconds
129
13- private val logger = LoggerFactory .getLogger(" path-utils" )
14-
15- @Blocking
1610fun zipFileSystem (
17- file : Path ,
11+ path : Path ,
1812 create : Boolean = false,
1913): FileSystem {
20- val uri = URI .create(" jar:${file.toUri()} " )
21-
22- if (create) {
23- return FileSystems .newFileSystem(uri, mapOf (" create" to true .toString()))
24- }
14+ val env = mapOf (" create" to create.toString())
2515
26- while ( true ) {
16+ for (provider in FileSystemProvider .installedProviders() ) {
2717 try {
28- return FileSystems .newFileSystem(uri, emptyMap<String , Any >())
29- } catch (e: FileSystemAlreadyExistsException ) {
30- logger.info(" Couldn't acquire access to $file file-system, waiting" , e)
31-
32- sleep(1 .seconds.inWholeMilliseconds)
18+ return provider.newFileSystem(path, env)
19+ } catch (_: UnsupportedOperationException ) {
3320 }
3421 }
22+
23+ throw ProviderNotFoundException (" Provider not found" )
3524}
3625
3726fun <T > Path.walk (action : Sequence <Path >.() -> T ) =
0 commit comments