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

Resolving sub-paths is not working correctly #37

Open
carlspring opened this issue Jul 18, 2020 · 2 comments
Open

Resolving sub-paths is not working correctly #37

carlspring opened this issue Jul 18, 2020 · 2 comments
Labels

Comments

@carlspring
Copy link
Contributor

In the TestPath there is already a test case to illustrate this. Currently, it looks like this:

  /**
   * Assertion to check that : <code>p.relativize(p.resolve(q)).equals(q)</code>
   */
  @Test
  public void testRelativizeResolveCombination() {
    Path p = Paths.get(clusterUri).resolve("/a/b");
    Path q = p.getFileSystem().getPath("c", "d");

    assertEquals(q, p.relativize(p.resolve(q)));
  }

If you change it to:

  /**
   * Assertion to check that : <code>p.relativize(p.resolve(q)).equals(q)</code>
   */
  @Test
  public void testRelativizeResolveCombination() {
    Path p = Paths.get(clusterUri).resolve("/a/b");
    Path q = p.getFileSystem().getPath("c", "d");
    Path qa = q.toAbsolutePath();
    
    assertEquals("/a/b/c/d", qa.toString());
    assertEquals(q, p.relativize(p.resolve(q)));
  }

You will see that the first assertion will fail, because the actual returned value for it is /c/d. The above will also fail, if you have Path q = p.resolve("c/d");. This is incorrect. Could you please fix it? :)

@damiencarol
Copy link
Owner

hello @carlspring and sorry for the long reply and thanks for the full description.
I will take a look at it soon.

@damiencarol
Copy link
Owner

made some tests and I don't see bug here.
Even the unit test is good.
Let me share more tests I made:

  /**
   * Assertion to check that : <code>p.relativize(p.resolve(q)).equals(q)</code>
   */
  @Test
  public void testRelativizeResolveCombination() {
    Path p = Paths.get(clusterUri).resolve("/a/b");
    Path q = p.getFileSystem().getPath("c", "d");

    assertEquals("/a/b", p.toString());
    assertEquals("c/d", q.toString());
    assertEquals("/a/b/c/d", p.resolve(q).toString());
    assertEquals(q, p.relativize(p.resolve(q)));

    Path qa = q.toAbsolutePath();
    assertEquals("c/d", q.toString());
    assertEquals("/c/d", qa.toString());
  }

If you convert q (which is c/d) to absolute path with q.toAbsolutePath() you can't have the complete /a/b/c/d path.
Because if you don't do "resolve" or "relativize" between the two paths you can't combine it.

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

No branches or pull requests

2 participants