Skip to content

Tests to show broken behavior when a symlink is named lib#372

Open
dchesterman wants to merge 1 commit into
nebula-plugins:mainfrom
dchesterman:dirSymlinks
Open

Tests to show broken behavior when a symlink is named lib#372
dchesterman wants to merge 1 commit into
nebula-plugins:mainfrom
dchesterman:dirSymlinks

Conversation

@dchesterman

Copy link
Copy Markdown
Contributor

These two tests are exactly the same expect one has a symlink named lib and the other is notlib (notlib can be anything and it works). The symlink named lib fails as it does not recognizes the file as a directory, but it is not since it is a link. It needs the relative path of the parent.

The link that is generated when the link is named lib has an extra ../ prefixed to it which makes it invalid.

I don't understand why the name of the link would make a difference here. Do you have any insight?

File sourceRoot = new File("/$sourceBase", sourceRelative)
File targetRoot = new File("/$sourceBase", targetPath.substring(sourceBasePath.length()))
Path relativeTarget = sourceRoot.isDirectory() ? sourceRoot.toPath().relativize(targetRoot.toPath()) : sourceRoot.parentFile.toPath().relativize(targetRoot.toPath())
println sourceBase

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I just put these in here to dump some output in the test output


class GradleUtilsIntegrationTest extends IntegrationSpec {

def 'verifySymlinkDirNested'() {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

builds a structure like so :

source
├── sourceDir
│   └── subdir
│       └── text.txt
└── notlib -> sourceDir/subdir

linkFile.asString() == 'sourceDir/subdir'
}

def 'verifySymlinkDirNestedWithLib'() {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

builds a structure like so :

source
├── sourceDir
│   └── subdir
│       └── text.txt
└── lib -> sourceDir/subdir

@@ -41,6 +43,13 @@ final class GradleUtils {
File sourceRoot = new File("/$sourceBase", sourceRelative)
File targetRoot = new File("/$sourceBase", targetPath.substring(sourceBasePath.length()))
Path relativeTarget = sourceRoot.isDirectory() ? sourceRoot.toPath().relativize(targetRoot.toPath()) : sourceRoot.parentFile.toPath().relativize(targetRoot.toPath())

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Interestingly enough, if I just take the fork out of this line and leave the following all tests pass

Path relativeTarget = sourceRoot.parentFile.toPath().relativize(targetRoot.toPath())

It still doesn't answer why the link is being evaluated differently, but I don't ever see a use case for the first option here anyways. I'm probably missing something, but whenever this is successful, it evaluates false. Again, I believe that is correct since it is a link and isDirectory() should return false for that.

Even if we are at a "directory symlink", we would still want the relative path to the target from the parent I believe. Otherwise the path you get is going up out of the "link directory" and back down to the target. Like ../path/to/target. Then the link is broken.

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.

1 participant