Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(382)

Unified Diff: pkg/analysis_server/lib/src/resource.dart

Issue 367453003: Handle relative paths in the output of "pub list-package-dirs". (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: pkg/analysis_server/lib/src/resource.dart
diff --git a/pkg/analysis_server/lib/src/resource.dart b/pkg/analysis_server/lib/src/resource.dart
index f5e5b7bd6b894efef893b747561717bbbb5aaa61..d988769a970eb06f99e0bb04d975ea1b08851b1d 100644
--- a/pkg/analysis_server/lib/src/resource.dart
+++ b/pkg/analysis_server/lib/src/resource.dart
@@ -47,6 +47,16 @@ abstract class Folder extends Resource {
* folders, including folders reachable via links).
*/
Stream<WatchEvent> get changes;
+
+ /**
+ * If the path [path] is a relative path, convert it to an absolute path
+ * by interpreting it relative to this folder. If it is already an aboslute
+ * path, then don't change it.
+ *
+ * However, regardless of whether [path] is relative or absolute, normalize
+ * it by removing path components of the form '.' or '..'.
+ */
+ String canonicalizePath(String path);
}
@@ -238,9 +248,7 @@ class _MemoryFolder extends _MemoryResource implements Folder {
super(provider, path);
@override
Resource getChild(String relPath) {
- relPath = posix.normalize(relPath);
- String childPath = posix.join(path, relPath);
- childPath = posix.normalize(childPath);
+ String childPath = canonicalizePath(relPath);
_MemoryResource resource = _provider._pathToResource[childPath];
if (resource == null) {
resource = new _MemoryFile(_provider, childPath);
@@ -274,6 +282,14 @@ class _MemoryFolder extends _MemoryResource implements Folder {
});
return streamController.stream;
}
+
+ @override
+ String canonicalizePath(String relPath) {
+ relPath = posix.normalize(relPath);
+ String childPath = posix.join(path, relPath);
+ childPath = posix.normalize(childPath);
+ return childPath;
+ }
}
@@ -397,8 +413,7 @@ class _PhysicalFolder extends _PhysicalResource implements Folder {
@override
Resource getChild(String relPath) {
- String childPath = join(_entry.absolute.path, relPath);
- return PhysicalResourceProvider.INSTANCE.getResource(childPath);
+ return PhysicalResourceProvider.INSTANCE.getResource(canonicalizePath(relPath));
}
@override
@@ -420,6 +435,11 @@ class _PhysicalFolder extends _PhysicalResource implements Folder {
@override
Stream<WatchEvent> get changes => new DirectoryWatcher(_entry.path).events;
+
+ @override
+ String canonicalizePath(String relPath) {
+ return normalize(join(_entry.absolute.path, relPath));
+ }
}

Powered by Google App Engine
This is Rietveld 408576698