OLD | NEW |
---|---|
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 part of dart.io; | 5 part of dart.io; |
6 | 6 |
7 class FileSystemEntityType { | 7 class FileSystemEntityType { |
8 static const FILE = const FileSystemEntityType._internal(0); | 8 static const FILE = const FileSystemEntityType._internal(0); |
9 static const DIRECTORY = const FileSystemEntityType._internal(1); | 9 static const DIRECTORY = const FileSystemEntityType._internal(1); |
10 static const LINK = const FileSystemEntityType._internal(2); | 10 static const LINK = const FileSystemEntityType._internal(2); |
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
336 request[2] = path2; | 336 request[2] = path2; |
337 return service.call(request).then((response) { | 337 return service.call(request).then((response) { |
338 if (_isErrorResponse(response)) { | 338 if (_isErrorResponse(response)) { |
339 throw _exceptionFromResponse(response, | 339 throw _exceptionFromResponse(response, |
340 "Error in FileSystemEntity.identical($path1, $path2)", ""); | 340 "Error in FileSystemEntity.identical($path1, $path2)", ""); |
341 } | 341 } |
342 return response; | 342 return response; |
343 }); | 343 }); |
344 } | 344 } |
345 | 345 |
346 static final RegExp _absoluteWindowsPathPattern = | |
347 new RegExp(r'^(\\\\|[a-zA-Z]:[/\\])'); | |
348 | |
349 /** | |
350 * Returns a [bool] indicating whether this object's path is absolute. | |
351 * | |
352 * On Windows, a path is absolute if it starts with \\ or a drive letter | |
353 * between a and z (upper or lower case) followed by :\ or :/. | |
354 * On non-Windows, a path is absolute if it starts with /. | |
355 */ | |
356 bool get isAbsolute { | |
357 if (Platform.isWindows) { | |
358 return path.startsWith(_absoluteWindowsPathPattern); | |
359 } else { | |
360 return path.startsWith('/'); | |
361 } | |
362 } | |
363 | |
364 /** | |
365 * Returns the absolute path to this file system entity, by prefixing | |
366 * a relative path with the current working directory, and returning | |
367 * an absolute path unchanged. | |
368 */ | |
369 String get absolutePath { | |
Søren Gjesse
2013/09/13 06:56:08
Thinking about this once more. Shouldn't this retu
| |
370 if (isAbsolute) return path; | |
371 String current = Directory.current.path; | |
372 if (current.endsWith('/') || | |
373 (Platform.isWindows && current.endsWith('\\'))) { | |
374 return '$current$path'; | |
375 } else { | |
376 return '$current${Platform.pathSeparator}$path'; | |
377 } | |
378 } | |
379 | |
346 | 380 |
347 /** | 381 /** |
348 * Synchronously checks whether two paths refer to the same object in the | 382 * Synchronously checks whether two paths refer to the same object in the |
349 * file system. | 383 * file system. |
350 * | 384 * |
351 * Comparing a link to its target returns false, as does comparing two links | 385 * Comparing a link to its target returns false, as does comparing two links |
352 * that point to the same target. To check the target of a link, use | 386 * that point to the same target. To check the target of a link, use |
353 * Link.target explicitly to fetch it. Directory links appearing | 387 * Link.target explicitly to fetch it. Directory links appearing |
354 * inside a path are followed, though, to find the file system object. | 388 * inside a path are followed, though, to find the file system object. |
355 * | 389 * |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
580 } | 614 } |
581 } | 615 } |
582 | 616 |
583 | 617 |
584 abstract class _FileSystemWatcher { | 618 abstract class _FileSystemWatcher { |
585 external factory _FileSystemWatcher(String path, int events, bool recursive); | 619 external factory _FileSystemWatcher(String path, int events, bool recursive); |
586 external static bool get isSupported; | 620 external static bool get isSupported; |
587 | 621 |
588 Stream<FileSystemEvent> get stream; | 622 Stream<FileSystemEvent> get stream; |
589 } | 623 } |
OLD | NEW |