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

relative() returns incorrect result #12

Closed
devoncarew opened this issue Mar 4, 2016 · 7 comments
Closed

relative() returns incorrect result #12

devoncarew opened this issue Mar 4, 2016 · 7 comments

Comments

@devoncarew
Copy link
Member

We're seeing a failure in flutter's tests (flutter/flutter#1709) which looks like a bug in path's relative() function:

from: /var/folders/00/0w978000h01000cxqpysvccm003j4x/T/flutter_toolsZUIVMq
to:   /Users/devoncarew/projects/flutter/flutter/packages

result = path.relative(to, from: from);

result: ../../../../../../Users/devoncarew/projects/flutter/flutter/packages

The relative result isn't correct. It's off by one in the number of times it should traverse up to the parent directory. From flutter_toolsZUIVMq it can only go up 5 times to /, but it has 6 ..'s in the relative result.

@nex3
Copy link
Member

nex3 commented Mar 4, 2016

This looks correct to me. It satisfies the invariant that p.join(from, p.relative(path, from: from)) refers to the same path as path.

import 'package:path/path.dart' as p;

void main() {
  var from = "/var/folders/00/0w978000h01000cxqpysvccm003j4x/T/flutter_toolsZUIVMq";
  var path = "/Users/devoncarew/projects/flutter/flutter/packages";

  print(p.normalize(from, p.join(p.relative(path, from: from))));
  // => /Users/devoncarew/projects/flutter/flutter/packages
}

Keep in mind that the from argument takes the place of the current directory. So if flutter_toolsZUIVMq is a file and you want a relative path that is valid within that file, from should be /var/folders/00/0w978000h01000cxqpysvccm003j4x/T.

@nex3 nex3 closed this as completed Mar 4, 2016
@devoncarew
Copy link
Member Author

flutter_toolsZUIVMq is a directory - we're creating a pubspec file in there and trying to write a relative path from there to the flutter package. (flutter_toolsZUIVMq/pubspec.yaml)

@nex3
Copy link
Member

nex3 commented Mar 4, 2016

In that case, the path you listed should work. I count six ..s, which matches the six path segments in from.

@devoncarew
Copy link
Member Author

But from flutter_toolsZUIVMq, it's only 5 segments up.

What's odd is that this test works on linux. And it does look like the relative path being created in the pubspec is bad.

@nex3
Copy link
Member

nex3 commented Mar 4, 2016

But from flutter_toolsZUIVMq, it's only 5 segments up.

Not if it's a directory and you're resolving a path inside it. You still have to .. up through flutter_toolsZUIVMq.

What's odd is that this test works on linux. And it does look like the relative path being created in the pubspec is bad.

I suspect the real issue here is OS X's symlinking of the /tmp directory. Relative paths that move up out of symlinked directories are unreliable; they can be resolved differently depending on what the resolving entity thinks the current working directory's path is.

@devoncarew
Copy link
Member Author

Ah, something to look into. I'll see if canonicalizing the paths helps.

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

No branches or pull requests

2 participants