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

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

Issue 23054008: Remove the Path class from dart:io (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed first round of review comments Created 7 years, 4 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/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 f608eb9123c8a24d0d992880856168ab135811dc..42b0c0262ffa52b35ca69aa96dc21da6d21e2abd 100644
--- a/pkg/http_server/lib/src/virtual_directory.dart
+++ b/pkg/http_server/lib/src/virtual_directory.dart
@@ -77,7 +77,7 @@ class _VirtualDirectory implements VirtualDirectory {
}
void serveRequest(HttpRequest request) {
- _locateResource(new Path('.'), request.uri.pathSegments.iterator..moveNext())
+ _locateResource('.', request.uri.pathSegments.iterator..moveNext())
.then((entity) {
if (entity == null) {
_serveErrorPage(HttpStatus.NOT_FOUND, request);
@@ -101,39 +101,39 @@ class _VirtualDirectory implements VirtualDirectory {
_errorCallback = callback;
}
- Future<FileSystemEntity> _locateResource(Path path,
+ Future<FileSystemEntity> _locateResource(String path,
Iterator<String> segments) {
- path = path.canonicalize();
- if (path.segments().first == "..") return new Future.value(null);
- Path fullPath() => new Path(root).join(path);
- return FileSystemEntity.type(fullPath().toNativePath(), followLinks: false)
+ path = normalize(path);
+ if (split(path).first == "..") return new Future.value(null);
+ String fullPath() => join(root, path);
+ return FileSystemEntity.type(fullPath(), followLinks: false)
.then((type) {
switch (type) {
case FileSystemEntityType.FILE:
if (segments.current == null) {
- return new File.fromPath(fullPath());
+ return new File(fullPath());
}
break;
case FileSystemEntityType.DIRECTORY:
if (segments.current == null) {
if (allowDirectoryListing) {
- return new Directory.fromPath(fullPath());
+ return new Directory(fullPath());
}
} else {
if (_invalidPathRegExp.hasMatch(segments.current)) break;
- return _locateResource(path.append(segments.current),
+ return _locateResource(join(path, segments.current),
segments..moveNext());
}
break;
case FileSystemEntityType.LINK:
if (followLinks) {
- return new Link.fromPath(fullPath()).target()
+ return new Link(fullPath()).target()
.then((target) {
- var targetPath = new Path(target).canonicalize();
- if (targetPath.isAbsolute) return null;
- targetPath = path.directoryPath.join(targetPath);
+ String targetPath = normalize(target);
+ if (isAbsolute(targetPath)) return null;
+ targetPath = join(dirname(path), targetPath);
return _locateResource(targetPath, segments);
});
}
@@ -254,7 +254,7 @@ $server
void add(String name, String modified, var size) {
if (size == null) size = "-";
if (modified == null) modified = "";
- var p = new Path(path).append(name).canonicalize().toString();
+ var p = normalize(join(path, name));
var entry =
''' <tr>
<td><a href="$p">$name</a></td>
@@ -272,11 +272,11 @@ $server
// TODO(ajohnsen): Consider async dir listing.
if (entity is File) {
var stat = entity.statSync();
- add(new Path(entity.path).filename,
+ add(basename(entity.path),
stat.modified.toString(),
stat.size);
} else if (entity is Directory) {
- add(new Path(entity.path).filename + '/',
+ add(basename(entity.path) + '/',
entity.statSync().modified.toString(),
null);
}

Powered by Google App Engine
This is Rietveld 408576698