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 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 * Synchronously renames this file system entity. Returns a [FileSystemEntity] | 214 * Synchronously renames this file system entity. Returns a [FileSystemEntity] |
215 * instance for the renamed entity. | 215 * instance for the renamed entity. |
216 * | 216 * |
217 * If [newPath] identifies an existing entity of the same type, that entity | 217 * If [newPath] identifies an existing entity of the same type, that entity |
218 * is replaced. If [newPath] identifies an existing entity of a different | 218 * is replaced. If [newPath] identifies an existing entity of a different |
219 * type, the operation fails and an exception is thrown. | 219 * type, the operation fails and an exception is thrown. |
220 */ | 220 */ |
221 FileSystemEntity renameSync(String newPath); | 221 FileSystemEntity renameSync(String newPath); |
222 | 222 |
223 /** | 223 /** |
| 224 * Resolves the path of a file system object relative to the |
| 225 * current working directory, resolving all symbolic links on |
| 226 * the path and resolving all '..' and '.' path segments. |
| 227 * [resolveSymbolicLinks] returns a [:Future<String>:] |
| 228 * |
| 229 * [resolveSymbolicLinks] uses the operating system's native filesystem api |
| 230 * to resolve the path, using the realpath function on linux and |
| 231 * Mac OS, and the GetFinalPathNameByHandle function on Windows. |
| 232 * If the path does not point to an existing file system object, |
| 233 * [resolveSymbolicLinks] completes the returned Future with an FileException. |
| 234 * |
| 235 * On Windows, symbolic links are resolved to their target before applying |
| 236 * a '..' that follows, and on other platforms, the '..' is applied to the |
| 237 * symbolic link without resolving it. The second behavior can be emulated |
| 238 * on Windows by processing any '..' segments before calling |
| 239 * [resolveSymbolicLinks]. One way of doing this is with the URI class: |
| 240 * [:new Uri.parse('.').resolveUri(new Uri.file(input)).toFilePath();], |
| 241 * since [resolve] removes '..' segments. |
| 242 */ |
| 243 Future<String> resolveSymbolicLinks() { |
| 244 // Get a new file service port for each request. We could also cache one. |
| 245 var service = _FileUtils._newServicePort(); |
| 246 List request = new List(2); |
| 247 request[0] = _RESOLVE_SYMBOLIC_LINKS_REQUEST; |
| 248 request[1] = path; |
| 249 return service.call(request).then((response) { |
| 250 if (_isErrorResponse(response)) { |
| 251 throw _exceptionFromResponse(response, |
| 252 "Cannot resolve symbolic links", |
| 253 path); |
| 254 } |
| 255 return response; |
| 256 }); |
| 257 } |
| 258 |
| 259 /** |
| 260 * Resolves the path of a file system object relative to the |
| 261 * current working directory, resolving all symbolic links on |
| 262 * the path and resolving all '..' and '.' path segments. |
| 263 * |
| 264 * [resolveSymbolicLinksSync] uses the operating system's native |
| 265 * filesystem api to resolve the path, using the realpath function |
| 266 * on linux and Mac OS, and the GetFinalPathNameByHandle function on Windows. |
| 267 * If the path does not point to an existing file system object, |
| 268 * [resolveSymbolicLinksSync] throws a FileException. |
| 269 * |
| 270 * On Windows, symbolic links are resolved to their target before applying |
| 271 * a '..' that follows, and on other platforms, the '..' is applied to the |
| 272 * symbolic link without resolving it. The second behavior can be emulated |
| 273 * on Windows by processing any '..' segments before calling |
| 274 * [resolveSymbolicLinks]. One way of doing this is with the URI class: |
| 275 * [:new Uri.parse('.').resolveUri(new Uri.file(input)).toFilePath();], |
| 276 * since [resolve] removes '..' segments. |
| 277 */ |
| 278 String resolveSymbolicLinksSync() { |
| 279 var result = _resolveSymbolicLinks(path); |
| 280 _throwIfError(result, "Cannot resolve symbolic links", path); |
| 281 return result; |
| 282 } |
| 283 |
| 284 |
| 285 /** |
224 * Calls the operating system's stat() function on the [path] of this | 286 * Calls the operating system's stat() function on the [path] of this |
225 * [FileSystemEntity]. Identical to [:FileStat.stat(this.path):]. | 287 * [FileSystemEntity]. Identical to [:FileStat.stat(this.path):]. |
226 * | 288 * |
227 * Returns a [:Future<FileStat>:] object containing the data returned by | 289 * Returns a [:Future<FileStat>:] object containing the data returned by |
228 * stat(). | 290 * stat(). |
229 * | 291 * |
230 * If the call fails, completes the future with a [FileStat] object | 292 * If the call fails, completes the future with a [FileStat] object |
231 * with .type set to | 293 * with .type set to |
232 * FileSystemEntityType.NOT_FOUND and the other fields invalid. | 294 * FileSystemEntityType.NOT_FOUND and the other fields invalid. |
233 */ | 295 */ |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 Stream<FileSystemEvent> watch({int events: FileSystemEvent.ALL, | 371 Stream<FileSystemEvent> watch({int events: FileSystemEvent.ALL, |
310 bool recursive: false}) | 372 bool recursive: false}) |
311 => new _FileSystemWatcher(_trimTrailingPathSeparators(path), | 373 => new _FileSystemWatcher(_trimTrailingPathSeparators(path), |
312 events, | 374 events, |
313 recursive).stream; | 375 recursive).stream; |
314 | 376 |
315 Future<FileSystemEntity> _delete({recursive: false}); | 377 Future<FileSystemEntity> _delete({recursive: false}); |
316 void _deleteSync({recursive: false}); | 378 void _deleteSync({recursive: false}); |
317 | 379 |
318 /** | 380 /** |
319 * Synchronously checks whether two paths refer to the same object in the | 381 * Checks whether two paths refer to the same object in the |
320 * file system. Returns a [:Future<bool>:] that completes with the result. | 382 * file system. Returns a [:Future<bool>:] that completes with the result. |
321 * | 383 * |
322 * Comparing a link to its target returns false, as does comparing two links | 384 * Comparing a link to its target returns false, as does comparing two links |
323 * that point to the same target. To check the target of a link, use | 385 * that point to the same target. To check the target of a link, use |
324 * Link.target explicitly to fetch it. Directory links appearing | 386 * Link.target explicitly to fetch it. Directory links appearing |
325 * inside a path are followed, though, to find the file system object. | 387 * inside a path are followed, though, to find the file system object. |
326 * | 388 * |
327 * Completes the returned Future with an error if one of the paths points | 389 * Completes the returned Future with an error if one of the paths points |
328 * to an object that does not exist. | 390 * to an object that does not exist. |
329 */ | 391 */ |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
474 | 536 |
475 /** | 537 /** |
476 * Synchronously checks if typeSync(path) returns | 538 * Synchronously checks if typeSync(path) returns |
477 * FileSystemEntityType.DIRECTORY. | 539 * FileSystemEntityType.DIRECTORY. |
478 */ | 540 */ |
479 static bool isDirectorySync(String path) => | 541 static bool isDirectorySync(String path) => |
480 (_getTypeSync(path, true) == FileSystemEntityType.DIRECTORY._type); | 542 (_getTypeSync(path, true) == FileSystemEntityType.DIRECTORY._type); |
481 | 543 |
482 external static _getType(String path, bool followLinks); | 544 external static _getType(String path, bool followLinks); |
483 external static _identical(String path1, String path2); | 545 external static _identical(String path1, String path2); |
| 546 external static _resolveSymbolicLinks(String path); |
484 | 547 |
485 static int _getTypeSync(String path, bool followLinks) { | 548 static int _getTypeSync(String path, bool followLinks) { |
486 var result = _getType(path, followLinks); | 549 var result = _getType(path, followLinks); |
487 _throwIfError(result, 'Error getting type of FileSystemEntity'); | 550 _throwIfError(result, 'Error getting type of FileSystemEntity'); |
488 return result; | 551 return result; |
489 } | 552 } |
490 | 553 |
491 static Future<int> _getTypeAsync(String path, bool followLinks) { | 554 static Future<int> _getTypeAsync(String path, bool followLinks) { |
492 // Get a new file service port for each request. We could also cache one. | 555 // Get a new file service port for each request. We could also cache one. |
493 var service = _FileUtils._newServicePort(); | 556 var service = _FileUtils._newServicePort(); |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
619 } | 682 } |
620 } | 683 } |
621 | 684 |
622 | 685 |
623 abstract class _FileSystemWatcher { | 686 abstract class _FileSystemWatcher { |
624 external factory _FileSystemWatcher(String path, int events, bool recursive); | 687 external factory _FileSystemWatcher(String path, int events, bool recursive); |
625 external static bool get isSupported; | 688 external static bool get isSupported; |
626 | 689 |
627 Stream<FileSystemEvent> get stream; | 690 Stream<FileSystemEvent> get stream; |
628 } | 691 } |
OLD | NEW |