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 a [FileSystemEntity] whose path is the absolute path to [this]. |
| 366 * The type of the returned instance is the type of [this]. |
| 367 * |
| 368 * The absolute path is computed by prefixing |
| 369 * a relative path with the current working directory, and returning |
| 370 * an absolute path unchanged. |
| 371 */ |
| 372 FileSystemEntity get absolute; |
| 373 |
| 374 String get _absolutePath { |
| 375 if (isAbsolute) return path; |
| 376 String current = Directory.current.path; |
| 377 if (current.endsWith('/') || |
| 378 (Platform.isWindows && current.endsWith('\\'))) { |
| 379 return '$current$path'; |
| 380 } else { |
| 381 return '$current${Platform.pathSeparator}$path'; |
| 382 } |
| 383 } |
| 384 |
346 | 385 |
347 /** | 386 /** |
348 * Synchronously checks whether two paths refer to the same object in the | 387 * Synchronously checks whether two paths refer to the same object in the |
349 * file system. | 388 * file system. |
350 * | 389 * |
351 * Comparing a link to its target returns false, as does comparing two links | 390 * 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 | 391 * that point to the same target. To check the target of a link, use |
353 * Link.target explicitly to fetch it. Directory links appearing | 392 * Link.target explicitly to fetch it. Directory links appearing |
354 * inside a path are followed, though, to find the file system object. | 393 * inside a path are followed, though, to find the file system object. |
355 * | 394 * |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
580 } | 619 } |
581 } | 620 } |
582 | 621 |
583 | 622 |
584 abstract class _FileSystemWatcher { | 623 abstract class _FileSystemWatcher { |
585 external factory _FileSystemWatcher(String path, int events, bool recursive); | 624 external factory _FileSystemWatcher(String path, int events, bool recursive); |
586 external static bool get isSupported; | 625 external static bool get isSupported; |
587 | 626 |
588 Stream<FileSystemEvent> get stream; | 627 Stream<FileSystemEvent> get stream; |
589 } | 628 } |
OLD | NEW |