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

Unified Diff: pkg/http_server/lib/src/virtual_directory.dart

Issue 17582007: Add support for following links, in VirtualDirectory. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Clean up code and tests. Created 7 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
« no previous file with comments | « no previous file | pkg/http_server/test/virtual_directory_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/http_server/lib/src/virtual_directory.dart
diff --git a/pkg/http_server/lib/src/virtual_directory.dart b/pkg/http_server/lib/src/virtual_directory.dart
index 680781e1c501eef310b210944639686fd49e596f..7cc18e087d4764809280b853bc9510bb3ec31c30 100644
--- a/pkg/http_server/lib/src/virtual_directory.dart
+++ b/pkg/http_server/lib/src/virtual_directory.dart
@@ -55,8 +55,8 @@ abstract class VirtualDirectory {
class _VirtualDirectory implements VirtualDirectory {
final String root;
- bool _allowDirectoryListing = false;
- bool _followLinks = true;
+ bool allowDirectoryListing = false;
+ bool followLinks = true;
_VirtualDirectory(this.root);
@@ -71,7 +71,7 @@ class _VirtualDirectory implements VirtualDirectory {
return _serveErrorPage(HttpStatus.NOT_FOUND, request);
}
- _locateResource(new Path(root), path.segments())
+ _locateResource(new Path('.'), path.segments())
.then((entity) {
if (entity == null) {
_serveErrorPage(HttpStatus.NOT_FOUND, request);
@@ -87,16 +87,19 @@ class _VirtualDirectory implements VirtualDirectory {
Future<FileSystemEntity> _locateResource(Path path,
Iterable<String> segments) {
- return FileSystemEntity.type(path.toNativePath(), followLinks: false)
+ Path fullPath() => new Path(root).join(path);
+ return FileSystemEntity.type(fullPath().toNativePath(), followLinks: false)
.then((type) {
switch (type) {
case FileSystemEntityType.FILE:
- if (segments.isEmpty) return new File.fromPath(path);
+ if (segments.isEmpty) return new File.fromPath(fullPath());
break;
case FileSystemEntityType.DIRECTORY:
if (segments.isEmpty) {
- if (_allowDirectoryListing) return new Directory.fromPath(path);
+ if (allowDirectoryListing) {
+ return new Directory.fromPath(fullPath());
+ }
} else {
return _locateResource(path.append(segments.first),
segments.skip(1));
@@ -105,7 +108,17 @@ class _VirtualDirectory implements VirtualDirectory {
case FileSystemEntityType.LINK:
if (followLinks) {
- // TODO
+ return new Link.fromPath(fullPath()).target()
+ .then((target) {
+ var targetPath = new Path(target).canonicalize();
+ if (targetPath.isAbsolute) return null;
+ targetPath = path.directoryPath.join(targetPath)
+ .canonicalize();
+ if (targetPath.segments().isEmpty ||
+ targetPath.segments().first == '..') return null;
+ return _locateResource(targetPath.append(segments.first),
+ segments.skip(1));
+ });
}
break;
}
« no previous file with comments | « no previous file | pkg/http_server/test/virtual_directory_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698