Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support symlink for NioFSWrappingFS #1275

Merged
merged 2 commits into from
Jun 21, 2023
Merged

Conversation

oldergod
Copy link
Member

No description provided.

@oldergod oldergod force-pushed the bquenaudon.2023-06-19.symlink branch from 5750324 to fea8371 Compare June 19, 2023 14:14
Base automatically changed from bquenaudon.2023-06-19.nomoresupportsfilehandle to bquenaudon.2023-06-19.getdefaultfilehandletest June 19, 2023 14:15
@oldergod oldergod force-pushed the bquenaudon.2023-06-19.symlink branch 6 times, most recently from c294f3a to 5a6e6d9 Compare June 19, 2023 15:04
Copy link
Member Author

@oldergod oldergod left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got confused a lot by JimFs (and its FS being in memory) but I think it's good now!

// TODO(Benoit) How do deal with multiple directories? Test with Windows someday.
private val delegateRoot = javaNioFileSystem.rootDirectories.first()

internal class NioFileSystemWrappingFileSystem(private val nioFileSystem: NioFileSystem) : NioSystemFileSystem() {
/**
* On a `java.nio.file.FileSystem`, `java.nio.file.Path` are stateful and hold a reference to the file system they
* got provided from. We need to [resolve][java.nio.file.Path.resolve] all okio paths before doing operations on the
* nio file system in order for things to work properly.
*/
private fun Path.resolve(readSymlink: Boolean = false): NioPath {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I could rename the method to something else

@oldergod oldergod marked this pull request as ready for review June 19, 2023 16:45
@oldergod oldergod requested a review from swankjesse June 19, 2023 16:45
@oldergod oldergod force-pushed the bquenaudon.2023-06-19.symlink branch from 5a6e6d9 to cc917b2 Compare June 19, 2023 18:10
path
}
}
val result = entries.mapTo(mutableListOf()) { entry -> dir / entry.toString() }
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

everything's simpler once you start using it correctly....

Files.createSymbolicLink(source.resolve(), target.resolve())
val sourceNioPath = source.resolve()
val targetNioPath =
if (source.isAbsolute && target.isRelative) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this necessary? Relative symlinks should be okay?

Base automatically changed from bquenaudon.2023-06-19.getdefaultfilehandletest to master June 20, 2023 16:24
@oldergod oldergod force-pushed the bquenaudon.2023-06-19.symlink branch from 9e5b9d1 to 00e31d5 Compare June 21, 2023 15:45
@oldergod oldergod enabled auto-merge June 21, 2023 15:45
@oldergod oldergod force-pushed the bquenaudon.2023-06-19.symlink branch from 00e31d5 to a681001 Compare June 21, 2023 15:45
@oldergod oldergod merged commit bc00d92 into master Jun 21, 2023
@oldergod oldergod deleted the bquenaudon.2023-06-19.symlink branch June 21, 2023 16:29
@@ -2211,6 +2247,7 @@ abstract class AbstractFileSystemTest(
@Test
fun openSymlinkSink() {
if (!supportsSymlink()) return
if (isJimFileSystem()) return
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants