Implemented FileChannel and symlink support

This commit is contained in:
Natty 2022-04-06 21:21:27 +02:00
parent b6decc8fd7
commit 0f903820fa
No known key found for this signature in database
GPG Key ID: 40AB22FA416C7019
3 changed files with 70 additions and 1 deletions

View File

@ -1,3 +1,6 @@
## 22.0.0.0-alpha.4
* `[PlutoRuntime]` Implemented optional `ResourceFileSystem` features
## 22.0.0.0-alpha.3
* `[SDK]` **Extensions are now published via GitHub actions**

View File

@ -22,7 +22,7 @@ object Versions {
const val isPrerelease = true
const val prereleaseName = "alpha"
const val prerealeaseUpdate = 3
const val prerealeaseUpdate = 4
val versionFull =
if (isPrerelease)

View File

@ -8,6 +8,8 @@ import org.plutoengine.mod.ModLoader;
import java.io.IOException;
import java.net.URI;
import java.nio.channels.AsynchronousFileChannel;
import java.nio.channels.FileChannel;
import java.nio.channels.SeekableByteChannel;
import java.nio.file.*;
import java.nio.file.attribute.BasicFileAttributes;
@ -17,6 +19,7 @@ import java.nio.file.spi.FileSystemProvider;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ExecutorService;
public class ResourceFileSystemProvider extends FileSystemProvider
{
@ -137,6 +140,69 @@ public class ResourceFileSystemProvider extends FileSystemProvider
return backingProvider.newByteChannel(backingPath, options, attrs);
}
@Override
public FileChannel newFileChannel(Path path, Set<? extends OpenOption> options, FileAttribute<?>... attrs) throws IOException
{
if (!(path instanceof ResourcePath rp))
throw new IllegalArgumentException("Expected a path of type %s!".formatted(ResourcePath.class));
var backingPath = rp.getBackingPath();
var backingFileSystem = backingPath.getFileSystem();
var backingProvider = backingFileSystem.provider();
return backingProvider.newFileChannel(backingPath, options, attrs);
}
@Override
public AsynchronousFileChannel newAsynchronousFileChannel(Path path, Set<? extends OpenOption> options, ExecutorService executor, FileAttribute<?>... attrs) throws IOException
{
return super.newAsynchronousFileChannel(path, options, executor, attrs);
}
@Override
public Path readSymbolicLink(Path link) throws IOException
{
if (!(link instanceof ResourcePath rp))
throw new IllegalArgumentException("Expected a path of type %s!".formatted(ResourcePath.class));
var backingPath = rp.getBackingPath();
var backingFileSystem = backingPath.getFileSystem();
var backingProvider = backingFileSystem.provider();
return backingProvider.readSymbolicLink(backingPath);
}
@Override
public void createSymbolicLink(Path link, Path target, FileAttribute<?>... attrs) throws IOException
{
if (!(link instanceof ResourcePath rpLink))
throw new IllegalArgumentException("Expected a path of type %s!".formatted(ResourcePath.class));
if (!(target instanceof ResourcePath rpTarget))
throw new IllegalArgumentException("Expected a path of type %s!".formatted(ResourcePath.class));
var linkBackingPath = rpLink.getBackingPath();
var linkBackingFileSystem = linkBackingPath.getFileSystem();
var linkBackingProvider = linkBackingFileSystem.provider();
var targetBackingPath = rpTarget.getBackingPath();
linkBackingProvider.createSymbolicLink(linkBackingPath, targetBackingPath, attrs);
}
@Override
public FileSystem newFileSystem(Path path, Map<String, ?> env) throws IOException
{
if (!(path instanceof ResourcePath rp))
throw new IllegalArgumentException("Expected a path of type %s!".formatted(ResourcePath.class));
var backingPath = rp.getBackingPath();
var backingFileSystem = backingPath.getFileSystem();
var backingProvider = backingFileSystem.provider();
return backingProvider.newFileSystem(path, env);
}
@Override
public synchronized DirectoryStream<Path> newDirectoryStream(Path dir, DirectoryStream.Filter<? super Path> filter) throws IOException
{