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 /** | 7 /** |
8 * The type of an entity on the file system, such as a file, directory, or link. | 8 * The type of an entity on the file system, such as a file, directory, or link. |
9 * | 9 * |
10 * These constants are used by the [FileSystemEntity] class | 10 * These constants are used by the [FileSystemEntity] class |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
262 * | 262 * |
263 * If [newPath] identifies an existing entity of the same type, that entity | 263 * If [newPath] identifies an existing entity of the same type, that entity |
264 * is replaced. If [newPath] identifies an existing entity of a different | 264 * is replaced. If [newPath] identifies an existing entity of a different |
265 * type, the operation fails and an exception is thrown. | 265 * type, the operation fails and an exception is thrown. |
266 */ | 266 */ |
267 FileSystemEntity renameSync(String newPath); | 267 FileSystemEntity renameSync(String newPath); |
268 | 268 |
269 /** | 269 /** |
270 * Resolves the path of a file system object relative to the | 270 * Resolves the path of a file system object relative to the |
271 * current working directory, resolving all symbolic links on | 271 * current working directory, resolving all symbolic links on |
272 * the path and resolving all '..' and '.' path segments. | 272 * the path and resolving all `..` and `.` path segments. |
273 * [resolveSymbolicLinks] returns a [:Future<String>:] | |
274 * | 273 * |
275 * [resolveSymbolicLinks] uses the operating system's native filesystem api | 274 * [resolveSymbolicLinks] uses the operating system's native |
276 * to resolve the path, using the realpath function on linux and | 275 * file system API to resolve the path, using the `realpath` function |
277 * Mac OS, and the GetFinalPathNameByHandle function on Windows. | 276 * on linux and Mac OS, and the `GetFinalPathNameByHandle` function on |
278 * If the path does not point to an existing file system object, | 277 * Windows. If the path does not point to an existing file system object, |
279 * [resolveSymbolicLinks] completes the returned Future with an FileSystemExce
ption. | 278 * `resolveSymbolicLinks` throws a `FileSystemException`. |
280 * | 279 * |
281 * On Windows, symbolic links are resolved to their target before applying | 280 * On Windows the `..` segments are resolved _before_ resolving the symbolic |
282 * a '..' that follows, and on other platforms, the '..' is applied to the | 281 * link, and on other platforms the symbolic links are _resolved to their |
283 * symbolic link without resolving it. The second behavior can be emulated | 282 * target_ before applying a `..` that follows. |
284 * on Windows by processing any '..' segments before calling | 283 * |
285 * [resolveSymbolicLinks]. One way of doing this is with the URI class: | 284 * To ensure the same behavior on all platforms resolve `..` segments before |
286 * [:new Uri.parse('.').resolveUri(new Uri.file(input)).toFilePath();], | 285 * calling `resolveSymbolicLinks`. One way of doing this is with the `Uri` |
287 * since [resolve] removes '..' segments. | 286 * class: |
| 287 * |
| 288 * var path = Uri.parse('.').resolveUri(new Uri.file(input)).toFilePath(); |
| 289 * if (path == '') path = '.'; |
| 290 * new File(path).resolveSymbolicLinks().then((resolved) { |
| 291 * print(resolved); |
| 292 * }); |
| 293 * |
| 294 * since `Uri.resolve` removes `..` segments. This will result in the Windows |
| 295 * behavior. |
288 */ | 296 */ |
289 Future<String> resolveSymbolicLinks() { | 297 Future<String> resolveSymbolicLinks() { |
290 return _IOService.dispatch(_FILE_RESOLVE_SYMBOLIC_LINKS, [path]) | 298 return _IOService.dispatch(_FILE_RESOLVE_SYMBOLIC_LINKS, [path]) |
291 .then((response) { | 299 .then((response) { |
292 if (_isErrorResponse(response)) { | 300 if (_isErrorResponse(response)) { |
293 throw _exceptionFromResponse(response, | 301 throw _exceptionFromResponse(response, |
294 "Cannot resolve symbolic links", | 302 "Cannot resolve symbolic links", |
295 path); | 303 path); |
296 } | 304 } |
297 return response; | 305 return response; |
298 }); | 306 }); |
299 } | 307 } |
300 | 308 |
301 /** | 309 /** |
302 * Resolves the path of a file system object relative to the | 310 * Resolves the path of a file system object relative to the |
303 * current working directory, resolving all symbolic links on | 311 * current working directory, resolving all symbolic links on |
304 * the path and resolving all '..' and '.' path segments. | 312 * the path and resolving all `..` and `.` path segments. |
305 * | 313 * |
306 * [resolveSymbolicLinksSync] uses the operating system's native | 314 * [resolveSymbolicLinksSync] uses the operating system's native |
307 * filesystem api to resolve the path, using the realpath function | 315 * file system API to resolve the path, using the `realpath` function |
308 * on linux and Mac OS, and the GetFinalPathNameByHandle function on Windows. | 316 * on linux and Mac OS, and the `GetFinalPathNameByHandle` function on |
309 * If the path does not point to an existing file system object, | 317 * Windows. If the path does not point to an existing file system object, |
310 * [resolveSymbolicLinksSync] throws a FileSystemException. | 318 * `resolveSymbolicLinksSync` throws a `FileSystemException`. |
311 * | 319 * |
312 * On Windows, symbolic links are resolved to their target before applying | 320 * On Windows the `..` segments are resolved _before_ resolving the symbolic |
313 * a '..' that follows, and on other platforms, the '..' is applied to the | 321 * link, and on other platforms the symbolic links are _resolved to their |
314 * symbolic link without resolving it. The second behavior can be emulated | 322 * target_ before applying a `..` that follows. |
315 * on Windows by processing any '..' segments before calling | 323 * |
316 * [resolveSymbolicLinks]. One way of doing this is with the URI class: | 324 * To ensure the same behavior on all platforms resolve `..` segments before |
317 * [:new Uri.parse('.').resolveUri(new Uri.file(input)).toFilePath();], | 325 * calling `resolveSymbolicLinksSync`. One way of doing this is with the `Uri` |
318 * since [resolve] removes '..' segments. | 326 * class: |
| 327 * |
| 328 * var path = Uri.parse('.').resolveUri(new Uri.file(input)).toFilePath(); |
| 329 * if (path == '') path = '.'; |
| 330 * var resolved = new File(path).resolveSymbolicLinksSync(); |
| 331 * print(resolved); |
| 332 * |
| 333 * since `Uri.resolve` removes `..` segments. This will result in the Windows |
| 334 * behavior. |
319 */ | 335 */ |
320 String resolveSymbolicLinksSync() { | 336 String resolveSymbolicLinksSync() { |
321 var result = _resolveSymbolicLinks(path); | 337 var result = _resolveSymbolicLinks(path); |
322 _throwIfError(result, "Cannot resolve symbolic links", path); | 338 _throwIfError(result, "Cannot resolve symbolic links", path); |
323 return result; | 339 return result; |
324 } | 340 } |
325 | 341 |
326 | 342 |
327 /** | 343 /** |
328 * Calls the operating system's stat() function on the [path] of this | 344 * Calls the operating system's stat() function on the [path] of this |
(...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
808 return buffer.toString(); | 824 return buffer.toString(); |
809 } | 825 } |
810 } | 826 } |
811 | 827 |
812 | 828 |
813 class _FileSystemWatcher { | 829 class _FileSystemWatcher { |
814 external static Stream<FileSystemEvent> watch( | 830 external static Stream<FileSystemEvent> watch( |
815 String path, int events, bool recursive); | 831 String path, int events, bool recursive); |
816 external static bool get isSupported; | 832 external static bool get isSupported; |
817 } | 833 } |
OLD | NEW |